From 5116fb5efb21b7846eebd4cbf186d3c067d5e819 Mon Sep 17 00:00:00 2001 From: bolade Date: Tue, 7 Oct 2025 12:44:27 +0100 Subject: [PATCH] Enhance tax extraction rules in DocumentProcessor to clarify handling of explicit and unclear tax amounts on receipts --- app/services/document_processor.py | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/app/services/document_processor.py b/app/services/document_processor.py index dbf1e27..d6acd45 100644 --- a/app/services/document_processor.py +++ b/app/services/document_processor.py @@ -97,7 +97,12 @@ class DocumentProcessor: - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") - If location not shown on receipt, return null for location (system will use user location as fallback) - - If tax_amount is NOT clearly shown on receipt, calculate it based on location: + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: * Ontario, Canada: 13% HST * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total * British Columbia, Canada: 12% (5% GST + 7% PST) @@ -106,9 +111,7 @@ class DocumentProcessor: * New York, USA: ~8.875% (varies by locality) * Texas, USA: 6.25% * For other locations, estimate based on typical rates - - Store calculated tax in "calculated_tax" field (set to null if tax clearly shown) - - If tax is clearly shown on receipt, use that value for tax_amount and set calculated_tax to null - - If tax is clearly shown on the receipt as 0%, set tax_amount to 0 and calculated_tax to null + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value DEPRECIATION RULES: - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings) @@ -250,7 +253,12 @@ class DocumentProcessor: - Format location as "Province/State, Country" (e.g., "Ontario, Canada" or "California, USA") - If location not shown on receipt, return null for location (system will use user location as fallback) - - If tax_amount is NOT clearly shown on receipt, calculate it based on location: + TAX EXTRACTION RULES (IMPORTANT): + - If tax is EXPLICITLY shown on receipt (even if $0 or 0%), use that exact value: + * If receipt shows "Tax: $0", "Tax: $0.00", "Tax (0%)", or similar → set tax_amount to 0.00 and calculated_tax to null + * If receipt shows any other tax amount → set tax_amount to that value and calculated_tax to null + + - If tax_amount is NOT shown or UNCLEAR on receipt, calculate it based on location: * Ontario, Canada: 13% HST * Quebec, Canada: 9.975% QST + 5% GST = 14.975% total * British Columbia, Canada: 12% (5% GST + 7% PST) @@ -259,8 +267,7 @@ class DocumentProcessor: * New York, USA: ~8.875% (varies by locality) * Texas, USA: 6.25% * For other locations, estimate based on typical rates - - Store calculated tax in "calculated_tax" field (set to null if tax clearly shown) - - If tax is clearly shown on receipt, use that value for tax_amount and set calculated_tax to null + * Store calculated tax in "calculated_tax" field and set tax_amount to the calculated value DEPRECIATION RULES: - Determine if item is a depreciable asset (vehicles, machinery, equipment, computers, furniture, buildings)