refactor create_shop_orders_on_payment to calculate tax after discounts and remove unused tax allocation
This commit is contained in:
@@ -112,9 +112,17 @@ def create_shop_orders_on_payment(sender, instance: OrderModel, created, **kwarg
|
|||||||
for it in items_list:
|
for it in items_list:
|
||||||
item_special_discounts += Decimal(str(it.special_discount_amount or 0))
|
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_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
|
commission_percent = getattr(shop, 'commission_percent', 0) or 0
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user