From bc37685f40f776977e745ebd18196f9fee28d799 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Mon, 16 Feb 2026 17:41:39 +0400 Subject: [PATCH] Fix Sport and Lottery Report: filter won/lost amounts correctly Issue: Amount columns were showing both won and lost transactions Fix: Only won=1 transactions now appear in amount columns Changes: - Added si.won field to SELECT query - Amount up to 500: only counts won=1 items - Amount over 500: only counts won=1 items - Grand total: still shows all amounts (won + lost) This ensures gambling report accuracy after won/lost bug fix. Co-Authored-By: Claude Sonnet 4.5 --- .../sport_and_lottery_report.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/taxes_az/taxes_az/report/sport_and_lottery_report/sport_and_lottery_report.py b/taxes_az/taxes_az/report/sport_and_lottery_report/sport_and_lottery_report.py index 8755908..23d7ad8 100644 --- a/taxes_az/taxes_az/report/sport_and_lottery_report/sport_and_lottery_report.py +++ b/taxes_az/taxes_az/report/sport_and_lottery_report/sport_and_lottery_report.py @@ -76,6 +76,7 @@ def get_data(filters): si.posting_date, si.grand_total, si.currency, + si.won, sii.amount ) .where( @@ -102,12 +103,14 @@ def get_data(filters): "amount_up_to_500": 0, "amount_over_500": 0, } - - # Distribute the item amount into the correct bucket - if item.amount <= 500: - processed_data[doc_name]["amount_up_to_500"] += item.amount - else: - processed_data[doc_name]["amount_over_500"] += item.amount + + # Distribute the item amount into the correct bucket ONLY if won = 1 + # Grand total already contains all amounts (won + lost) + if item.won == 1: + if item.amount <= 500: + processed_data[doc_name]["amount_up_to_500"] += item.amount + else: + processed_data[doc_name]["amount_over_500"] += item.amount # Return the processed data as a list of dictionaries return list(processed_data.values())