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 <noreply@anthropic.com>
This commit is contained in:
Ali 2026-02-16 17:41:39 +04:00
parent bc08937278
commit bc37685f40
1 changed files with 9 additions and 6 deletions

View File

@ -76,6 +76,7 @@ def get_data(filters):
si.posting_date, si.posting_date,
si.grand_total, si.grand_total,
si.currency, si.currency,
si.won,
sii.amount sii.amount
) )
.where( .where(
@ -102,12 +103,14 @@ def get_data(filters):
"amount_up_to_500": 0, "amount_up_to_500": 0,
"amount_over_500": 0, "amount_over_500": 0,
} }
# Distribute the item amount into the correct bucket # Distribute the item amount into the correct bucket ONLY if won = 1
if item.amount <= 500: # Grand total already contains all amounts (won + lost)
processed_data[doc_name]["amount_up_to_500"] += item.amount if item.won == 1:
else: if item.amount <= 500:
processed_data[doc_name]["amount_over_500"] += item.amount 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 the processed data as a list of dictionaries
return list(processed_data.values()) return list(processed_data.values())