Commits

Anderson Santos committed 0e1ca27

adjustments for calculating price discount with taxes

  • Participants
  • Parent commits 3ab5730

Comments (0)

Files changed (4)

File satchmo/apps/product/models.py

         for lineitem in order.orderitem_set.all():
             lid = lineitem.id
             price = lineitem.line_item_price
+            #Mandrill: Anderson - I added this line so the discount will consider tax
+            tax_discount = config_value('TAX', 'INCLUDE_TAX_ON_DISCOUNTS');
+            if tax_discount:
+                price += lineitem.tax
             if lineitem.product.is_discountable and (allvalid or lineitem.product.slug in validproducts):
                 discounted[lid] = price
         signals.discount_filter_items.send(

File satchmo/apps/satchmo_store/shop/models.py

     shipping_with_tax = property(_shipping_with_tax)
 
     def sub_total_with_tax(self):
+        #with discount
         return reduce(operator.add, [o.total_with_tax for o in self.orderitem_set.all()])
 
+    def line_item_price(self):
+        #without discount
+        return reduce(operator.add, [o.unit_price_with_tax*o.quantity for o in self.orderitem_set.all()])
+
     def update_status(self, status):
         """WARNING: To just change order status, use Order.add_status().
         This method is called back when OrderStatus is saved and does not create required object."""

File satchmo/apps/tax/config.py

     default=False
 ))
 
+INCLUDE_TAX_ON_DISCOUNTS = config_register(BooleanValue(TAX_GROUP,
+    'INCLUDE_TAX_ON_DISCOUNTS',
+    description=_("Include taxes when calculating product discount"),
+    help_text=_("If true, will consider price with taxes to calculate discount."),
+    default=False
+))
+
 TAX_AREA_ADDRESS = config_register(
         StringValue(TAX_GROUP,
         'TAX_AREA_ADDRESS',

File satchmo/apps/tax/modules/percent/processor.py

 
         sub_total = Decimal("0.00")
         for item in order.orderitem_set.filter(product__taxable=True):
-            sub_total += item.sub_total
+            if config_value("TAX","INCLUDE_TAX_ON_DISCOUNTS"):
+                sub_total += item.unit_price*item.quantity
+            else:
+                sub_total += item.sub_total
         
         itemtax = sub_total * (percent/100)
         taxrates = {'%i%%' % percent :  itemtax}