Changeset - 1c02325bc449
[Not reviewed]
0 1 0
Lance Edgar (lance) - 2 years ago 2022-09-06 16:32:19
lance@edbob.org
Add basic per-item discount support for custorders
1 file changed with 23 insertions and 0 deletions:
0 comments (0 inline, 0 general)
rattail/batch/custorder.py
Show inline comments
 
@@ -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:
0 comments (0 inline, 0 general)