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