Update discount logic (more hypothetical, we don't store rounding on cart positions atm)

This commit is contained in:
Raphael Michel
2025-08-13 16:05:07 +02:00
parent c48fd7d3e1
commit 81eaf79e5b
2 changed files with 7 additions and 5 deletions

View File

@@ -1430,11 +1430,12 @@ class CartManager:
)
for cp, (new_price, discount) in zip(positions, discount_results):
if cp.price != new_price or cp.discount_id != (discount.pk if discount else None):
diff += new_price - cp.price
if (cp.price - cp.price_includes_rounding_correction) != new_price or cp.discount_id != (discount.pk if discount else None):
diff += new_price - (cp.price - cp.price_includes_rounding_correction)
cp.price = new_price
cp.price_includes_rounding_correction = Decimal("0.00")
cp.discount = discount
cp.save(update_fields=['price', 'discount'])
cp.save(update_fields=['price', 'price_includes_rounding_correction', 'discount'])
return diff

View File

@@ -910,10 +910,11 @@ def _check_positions(event: Event, now_dt: datetime, time_machine_now_dt: dateti
]
)
for cp, (new_price, discount) in zip(sorted_positions, discount_results):
if cp.price != new_price or cp.discount_id != (discount.pk if discount else None):
if cp.price - cp.price_includes_rounding_correction != new_price or cp.discount_id != (discount.pk if discount else None):
cp.price = new_price
cp.price_includes_rounding_correction = Decimal("0.00")
cp.discount = discount
cp.save(update_fields=['price', 'discount'])
cp.save(update_fields=['price', 'price_includes_rounding_correction', 'discount'])
# After applying discounts, add-on positions might still have a reference to the *old* version of the
# parent position, which can screw up ordering later since the system sees inconsistent data.