Changeset - 331828e9ced1
[Not reviewed]
0 3 0
Lance Edgar (lance) - 3 years ago 2021-11-06 20:31:02
lance@edbob.org
Add support for finding past items, for new custorder

also misc. tweaks for new custorder feature
3 files changed with 46 insertions and 3 deletions:
0 comments (0 inline, 0 general)
rattail/app.py
Show inline comments
 
@@ -119,6 +119,10 @@ class AppHandler(object):
 
            self.auth_handler = factory(self.config, **kwargs)
 
        return self.auth_handler
 

	
 
    def get_batch_handler(self, key, **kwargs):
 
        from rattail.batch import get_batch_handler
 
        return get_batch_handler(self.config, key, **kwargs)
 

	
 
    def get_board_handler(self, **kwargs):
 
        if not hasattr(self, 'board_handler'):
 
            from rattail.board import get_board_handler
rattail/batch/custorder.py
Show inline comments
 
@@ -35,6 +35,7 @@ from sqlalchemy import orm
 

	
 
from rattail.db import model
 
from rattail.batch import BatchHandler
 
from rattail.util import OrderedDict
 

	
 

	
 
class CustomerOrderBatchHandler(BatchHandler):
 
@@ -410,14 +411,43 @@ class CustomerOrderBatchHandler(BatchHandler):
 
                                  "{}.custom_product_autocomplete() "
 
                                  "method.".format(__class__.__name__))
 

	
 
    def get_past_orders(self, batch, **kwargs):
 
        """
 
        Retrieve a list of past orders for the batch contact.
 
        """
 
        session = self.app.get_session(batch)
 
        model = self.model
 
        orders = session.query(model.CustomerOrder)
 

	
 
        contact = self.get_contact(batch)
 
        if isinstance(contact, model.Customer):
 
            orders = orders.filter(model.CustomerOrder.customer == contact)
 
        else:
 
            orders = orders.filter(model.CustomerOrder.person == contact)
 

	
 
        orders = orders.order_by(model.CustomerOrder.created.desc())
 
        return orders.all()
 

	
 
    def get_past_products(self, batch, **kwargs):
 
        """
 
        Should return a (possibly empty) list of products which have
 
        been ordered in the past by the customer who is associated
 
        with the given batch.
 
        """
 
        # TODO: should crawl the rattail order history here
 
        return []
 
        session = self.app.get_session(batch)
 
        model = self.model
 
        products = OrderedDict()
 

	
 
        # track down all order items for batch contact
 
        orders = self.get_past_orders(batch)
 
        for order in orders:
 
            for item in order.items:
 
                product = item.product
 
                if product:
 
                    # we only want the first match for each product
 
                    products.setdefault(product.uuid, product)
 

	
 
        return list(products.values())
 

	
 
    def get_product_info(self, batch, product, **kwargs):
 
        """
 
@@ -438,6 +468,7 @@ class CustomerOrderBatchHandler(BatchHandler):
 
            'unit_price_display': products.render_price(product.regular_price),
 
            'department_name': product.department.name if product.department else None,
 
            'vendor_name': vendor.name if vendor else None,
 
            'url': products.get_url(product),
 
            'image_url': products.get_image_url(product),
 
            'uom_choices': self.uom_choices_for_product(product),
 
        }
 
@@ -445,7 +476,7 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        case_price = None
 
        if product.regular_price and product.regular_price is not None:
 
            case_size = self.get_case_size_for_product(product)
 
            case_price = case_size * product.regular_price.price
 
            case_price = (case_size or 1) * product.regular_price.price
 
            case_price = case_price.quantize(decimal.Decimal('0.01'))
 
        info['case_price'] = six.text_type(case_price) if case_price is not None else None
 
        info['case_price_display'] = self.app.render_currency(case_price)
rattail/products.py
Show inline comments
 
@@ -180,6 +180,14 @@ class ProductsHandler(GenericHandler):
 

	
 
        return products
 

	
 
    def get_url(self, product, **kwargs):
 
        """
 
        Return the Tailbone "view" URL for the given product.
 
        """
 
        base_url = self.config.base_url()
 
        if base_url:
 
            return '{}/products/{}'.format(base_url, product.uuid)
 

	
 
    def get_image_url(self, product=None, upc=None, **kwargs):
 
        """
 
        Return the preferred image URL for the given UPC or product.
0 comments (0 inline, 0 general)