fix: Calculate loyalty discount income from specific reward line amounts instead of gross sales.
This commit is contained in:
parent
98a739b9d3
commit
6640b0bc98
@ -40,17 +40,18 @@ class PosSession(models.Model):
|
|||||||
# Net: $0
|
# Net: $0
|
||||||
# We want to record: Credit Income $100, Debit Expense $100.
|
# We want to record: Credit Income $100, Debit Expense $100.
|
||||||
|
|
||||||
# We can sum the positive lines to get the "Sale Value".
|
# Calculate the exact discount amount applied by loyalty rewards
|
||||||
gross_amount = sum(
|
# This avoids treating downpayments or refunds as "100% Discount Income"
|
||||||
line.price_subtotal
|
discount_amount = sum(
|
||||||
|
abs(line.price_subtotal)
|
||||||
for line in order.lines
|
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
|
continue
|
||||||
|
|
||||||
amounts = _get_amounts(gross_amount, order.date_order)
|
amounts = _get_amounts(discount_amount, order.date_order)
|
||||||
|
|
||||||
# Create Credit Line (Income)
|
# Create Credit Line (Income)
|
||||||
# We use _credit_amounts helper logic style manually
|
# We use _credit_amounts helper logic style manually
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user