From 66d79107705eb7b7c6b34f8f3fb911915f40fae6 2021-11-27 19:07:33 From: Lance Edgar Date: 2021-11-27 19:07:33 Subject: [PATCH] Add some sale pricing logic for custorder batch --- diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index 05b544410807fe8c0ce258778ef6ef75b4b9fc81..4b1c50d960013362c131f1ebc814bef81b9d93ab 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -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)