fix: Calculate loyalty discount income from specific reward line amounts instead of gross sales.

This commit is contained in:
Suherdy Yacob 2026-03-09 14:49:58 +07:00
parent 98a739b9d3
commit 6640b0bc98

View File

@ -40,17 +40,18 @@ class PosSession(models.Model):
# Net: $0
# We want to record: Credit Income $100, Debit Expense $100.
# We can sum the positive lines to get the "Sale Value".
gross_amount = sum(
line.price_subtotal
# Calculate the exact discount amount applied by loyalty rewards
# This avoids treating downpayments or refunds as "100% Discount Income"
discount_amount = sum(
abs(line.price_subtotal)
for line in order.lines
if line.price_subtotal > 0
if line.price_subtotal < 0 and (getattr(line, 'is_reward_line', False) or getattr(line, 'reward_id', False))
)
if float_is_zero(gross_amount, precision_rounding=self.currency_id.rounding):
if float_is_zero(discount_amount, precision_rounding=self.currency_id.rounding):
continue
amounts = _get_amounts(gross_amount, order.date_order)
amounts = _get_amounts(discount_amount, order.date_order)
# Create Credit Line (Income)
# We use _credit_amounts helper logic style manually