diff --git a/rattail/batch/custorder.py b/rattail/batch/custorder.py index 87c4ce375f1513f94fc03463eb290907f09250e1..5b795190cd58cd96d886d09b2835209e2d51f8b9 100644 --- a/rattail/batch/custorder.py +++ b/rattail/batch/custorder.py @@ -125,6 +125,15 @@ class CustomerOrderBatchHandler(BatchHandler): 'allow_unknown_product', default=False) + def allow_item_discounts(self): + """ + Returns boolean indicating whether per-item discounts are + allowed. + """ + return self.config.getbool('rattail.custorders', + 'allow_item_discounts', + default=False) + def product_price_may_be_questionable(self): """ Returns a boolean indicating whether "any" product's price may @@ -598,8 +607,13 @@ class CustomerOrderBatchHandler(BatchHandler): row.product = product row.order_quantity = order_quantity row.order_uom = order_uom + if 'price_needs_confirmation' in kwargs: row.price_needs_confirmation = kwargs['price_needs_confirmation'] + + if self.allow_item_discounts(): + row.discount_percent = kwargs.get('discount_percent') or 0 + self.add_row(batch, row) return row @@ -634,6 +648,10 @@ class CustomerOrderBatchHandler(BatchHandler): row.pending_product = pending_product row.order_quantity = order_quantity row.order_uom = order_uom + + if self.allow_item_discounts(): + row.discount_percent = kwargs.get('discount_percent') or 0 + self.add_row(batch, row) return row @@ -745,6 +763,11 @@ class CustomerOrderBatchHandler(BatchHandler): row.total_price = row.unit_price * row.order_quantity if row.order_uom == self.enum.UNIT_OF_MEASURE_CASE: row.total_price *= (row.case_quantity or 1) + if row.discount_percent: + row.total_price = (float(row.total_price) + * (100 - float(row.discount_percent)) + / 100.0) + row.total_price = decimal.Decimal('{:0.2f}'.format(row.total_price)) # update total price for batch too, if it changed if row.total_price != old_total: