diff --git a/backend/order/signals.py b/backend/order/signals.py index c157a1c..121ac35 100644 --- a/backend/order/signals.py +++ b/backend/order/signals.py @@ -112,9 +112,17 @@ def create_shop_orders_on_payment(sender, instance: OrderModel, created, **kwarg for it in items_list: item_special_discounts += Decimal(str(it.special_discount_amount or 0)) - # Proportionally allocate cart-level discount and tax + # Proportionally allocate cart-level discount allocated_discount = (Decimal(str(order_discount)) * Decimal(str(shop_subtotal)) / Decimal(str(total_subtotal))) if order_discount else Decimal('0') - allocated_tax = (Decimal(str(order_tax)) * Decimal(str(shop_subtotal)) / Decimal(str(total_subtotal))) if order_tax else Decimal('0') + + # Calculate tax on shop's amount after all discounts + # Tax rate from settings (default 10%) + tax_rate = Decimal(str(getattr(settings, 'DEFAULT_TAX_RATE', 10))) + base_for_tax = max( + Decimal('0'), + Decimal(str(shop_subtotal)) - item_level_discounts - item_special_discounts - allocated_discount + ) + allocated_tax = base_for_tax * (tax_rate / Decimal('100')) commission_percent = getattr(shop, 'commission_percent', 0) or 0 try: