Add basic per-item discount support for custorders
This commit is contained in:
parent
110c684682
commit
1c02325bc4
|
@ -125,6 +125,15 @@ class CustomerOrderBatchHandler(BatchHandler):
|
||||||
'allow_unknown_product',
|
'allow_unknown_product',
|
||||||
default=False)
|
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):
|
def product_price_may_be_questionable(self):
|
||||||
"""
|
"""
|
||||||
Returns a boolean indicating whether "any" product's price may
|
Returns a boolean indicating whether "any" product's price may
|
||||||
|
@ -598,8 +607,13 @@ class CustomerOrderBatchHandler(BatchHandler):
|
||||||
row.product = product
|
row.product = product
|
||||||
row.order_quantity = order_quantity
|
row.order_quantity = order_quantity
|
||||||
row.order_uom = order_uom
|
row.order_uom = order_uom
|
||||||
|
|
||||||
if 'price_needs_confirmation' in kwargs:
|
if 'price_needs_confirmation' in kwargs:
|
||||||
row.price_needs_confirmation = kwargs['price_needs_confirmation']
|
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)
|
self.add_row(batch, row)
|
||||||
return row
|
return row
|
||||||
|
|
||||||
|
@ -634,6 +648,10 @@ class CustomerOrderBatchHandler(BatchHandler):
|
||||||
row.pending_product = pending_product
|
row.pending_product = pending_product
|
||||||
row.order_quantity = order_quantity
|
row.order_quantity = order_quantity
|
||||||
row.order_uom = order_uom
|
row.order_uom = order_uom
|
||||||
|
|
||||||
|
if self.allow_item_discounts():
|
||||||
|
row.discount_percent = kwargs.get('discount_percent') or 0
|
||||||
|
|
||||||
self.add_row(batch, row)
|
self.add_row(batch, row)
|
||||||
return row
|
return row
|
||||||
|
|
||||||
|
@ -745,6 +763,11 @@ class CustomerOrderBatchHandler(BatchHandler):
|
||||||
row.total_price = row.unit_price * row.order_quantity
|
row.total_price = row.unit_price * row.order_quantity
|
||||||
if row.order_uom == self.enum.UNIT_OF_MEASURE_CASE:
|
if row.order_uom == self.enum.UNIT_OF_MEASURE_CASE:
|
||||||
row.total_price *= (row.case_quantity or 1)
|
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
|
# update total price for batch too, if it changed
|
||||||
if row.total_price != old_total:
|
if row.total_price != old_total:
|
||||||
|
|
Loading…
Reference in a new issue