Changeset - 66d79107705e
[Not reviewed]
0 1 0
Lance Edgar (lance) - 3 years ago 2021-11-27 19:07:33
lance@edbob.org
Add some sale pricing logic for custorder batch
1 file changed with 22 insertions and 1 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -36,6 +36,7 @@ from sqlalchemy import orm
 
from rattail.db import model
 
from rattail.batch import BatchHandler
 
from rattail.util import OrderedDict
 
from rattail.time import localtime
 

	
 

	
 
class CustomerOrderBatchHandler(BatchHandler):
 
@@ -473,10 +474,30 @@ class CustomerOrderBatchHandler(BatchHandler):
 
            'uom_choices': self.uom_choices_for_product(product),
 
        }
 

	
 
        # TODO: this was somewhat copied from
 
        # tailbone.views.products.render_price() - should make it part
 
        # of the products handler instead?
 
        sale_price = None
 
        if not product.not_for_sale:
 
            sale_price = product.current_price
 
            if sale_price:
 
                if sale_price.price:
 
                    info['sale_price'] = float(sale_price.price)
 
                info['sale_price_display'] = products.render_price(sale_price)
 
                sale_ends = sale_price.ends
 
                if sale_ends:
 
                    sale_ends = localtime(self.config, sale_ends, from_utc=True).date()
 
                    info['sale_ends'] = six.text_type(sale_ends)
 
                    info['sale_ends_display'] = self.app.render_date(sale_ends)
 

	
 
        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 or 1) * product.regular_price.price
 
            # use sale price if there is one, else normal unit price
 
            unit_price = product.regular_price.price
 
            if sale_price:
 
                unit_price = sale_price.price
 
            case_price = (case_size or 1) * unit_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)
0 comments (0 inline, 0 general)