From dc0c65ea7b0532470c4cc5243c6b1a974d76f9c9 2021-11-06 17:35:51 From: Lance Edgar Date: 2021-11-06 17:35:51 Subject: [PATCH] Add some "case price" logic for custorder batch --- diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index 44445c8199cd672f235ab2dc38d4c6d422d51d4e..3d69ac183ebe650d6bab7b73f5a65dd722a20f2e 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -27,6 +27,7 @@ Handler for "customer order" batches from __future__ import unicode_literals, absolute_import, division import re +import decimal import six import sqlalchemy as sa @@ -335,6 +336,17 @@ class CustomerOrderBatchHandler(BatchHandler): if cost: return cost.case_size + def get_case_price_for_row(self, row): + """ + Calculate and return the per-case price for the given row. + + NB. we do not store case price, only unit price. maybe that + should change some day.. + """ + if row.unit_price is not None: + case_price = row.unit_price * (row.case_quantity or 1) + return case_price.quantize(decimal.Decimal('0.01')) + # TODO: this method should maybe not exist? and caller just # invokes the handler directly instead? def customer_autocomplete(self, session, term, **kwargs): @@ -408,12 +420,22 @@ class CustomerOrderBatchHandler(BatchHandler): 'uuid': product.uuid, 'upc': six.text_type(product.upc), 'upc_pretty': product.upc.pretty(), - 'unit_price_display': products.render_price(product.regular_price), 'full_description': product.full_description, + 'size': product.size, + 'case_quantity': self.app.render_quantity(self.get_case_size_for_product(product)), + 'unit_price_display': products.render_price(product.regular_price), 'image_url': products.get_image_url(product), 'uom_choices': self.uom_choices_for_product(product), } + 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_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) + key = self.config.product_key() if key == 'upc': info['key'] = info['upc_pretty']