From 6640b0bc98360e3586870319ad158471fe56cf1a Mon Sep 17 00:00:00 2001 From: Suherdy Yacob Date: Mon, 9 Mar 2026 14:49:58 +0700 Subject: [PATCH] fix: Calculate loyalty discount income from specific reward line amounts instead of gross sales. --- models/pos_session.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/models/pos_session.py b/models/pos_session.py index 37e7b96..617aabd 100644 --- a/models/pos_session.py +++ b/models/pos_session.py @@ -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