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
 
@@ -122,12 +122,21 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        allowed on new orders.
 
        """
 
        return self.config.getbool('rattail.custorders',
 
                                   '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
 
        be questionable.  So this isn't saying that a price *is*
 
        questionable but rather that it *may* be, if the user
 
        indicates it.  (That checkbox is only shown for the user if
 
@@ -595,14 +604,19 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        """
 
        row = self.make_row()
 
        row.item_entry = product.uuid
 
        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
 

	
 
    def add_pending_product(self, batch, pending_info,
 
                            order_quantity, order_uom,
 
                            **kwargs):
 
@@ -631,12 +645,16 @@ class CustomerOrderBatchHandler(BatchHandler):
 

	
 
        # make a new row, w/ pending product
 
        row = self.make_row()
 
        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
 

	
 
    def make_pending_product(self, **kwargs):
 
        products_handler = self.app.get_products_handler()
 
        if 'status_code' not in kwargs:
 
@@ -742,12 +760,17 @@ class CustomerOrderBatchHandler(BatchHandler):
 
        elif not row.unit_price:
 
            row.total_price = 0
 
        else:
 
            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:
 
            batch = row.batch
 
            batch.total_price = ((batch.total_price or 0)
 
                                 + (row.total_price or 0)
0 comments (0 inline, 0 general)