From f6227567d42f8eb25d5518f6c266d39a735a3b79 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Wed, 11 Feb 2026 22:28:46 +0400 Subject: [PATCH] add debug logging to vat allocation report --- .../vat_allocation_report.py | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/taxes_az/taxes_az/report/vat_allocation_report/vat_allocation_report.py b/taxes_az/taxes_az/report/vat_allocation_report/vat_allocation_report.py index 88a4772..001272a 100644 --- a/taxes_az/taxes_az/report/vat_allocation_report/vat_allocation_report.py +++ b/taxes_az/taxes_az/report/vat_allocation_report/vat_allocation_report.py @@ -81,7 +81,20 @@ def get_empty_row(vat_name=""): def get_data(filters): """Get VAT allocation documents and calculate values""" - # DEBUG: Log incoming filters + # DEBUG: Log incoming filters (always log to file) + import json + debug_msg = f"VAT Report called with filters: {json.dumps(filters, default=str)}" + + # Write to file for debugging + try: + with open('/tmp/vat_report_debug.log', 'a') as f: + from datetime import datetime + f.write(f"\n{'='*80}\n") + f.write(f"Time: {datetime.now()}\n") + f.write(f"{debug_msg}\n") + except: + pass + frappe.log_error(title="VAT Report Filters", message=f"Incoming filters: {filters}") # Return empty row if filters are not provided (needed for Formula Editor) @@ -117,20 +130,54 @@ def get_data(filters): # Find VAT allocation document (max one result due to autoname format) vat_name = f"VAT-{year}-{month}" + + # Log to file + try: + with open('/tmp/vat_report_debug.log', 'a') as f: + f.write(f"Looking for document: {vat_name}\n") + except: + pass + frappe.log_error(title="VAT Report: Doc Search", message=f"Looking for document: {vat_name}") if not frappe.db.exists("VAT allocation", vat_name): + try: + with open('/tmp/vat_report_debug.log', 'a') as f: + f.write(f"Document NOT FOUND: {vat_name}\n") + f.write(f"Returning empty row\n") + except: + pass frappe.log_error(title="VAT Report: Not Found", message=f"Document '{vat_name}' does not exist in database\nReturning empty row with name: {vat_name}") return [get_empty_row(vat_name)] # Check if submitted docstatus = frappe.db.get_value("VAT allocation", vat_name, "docstatus") + + try: + with open('/tmp/vat_report_debug.log', 'a') as f: + f.write(f"Document FOUND: {vat_name}, docstatus={docstatus}\n") + except: + pass + frappe.log_error(title="VAT Report: Doc Status", message=f"Document: {vat_name}\nDocstatus: {docstatus}\nSubmitted: {docstatus == 1}") if docstatus != 1: + try: + with open('/tmp/vat_report_debug.log', 'a') as f: + f.write(f"Document NOT SUBMITTED (docstatus={docstatus})\n") + except: + pass frappe.log_error(title="VAT Report: Not Submitted", message=f"Document '{vat_name}' exists but not submitted (docstatus={docstatus})\nReturning empty row") return [get_empty_row(vat_name)] row = calculate_row_data(vat_name) + + try: + with open('/tmp/vat_report_debug.log', 'a') as f: + f.write(f"Calculated row data: {row}\n") + f.write(f"{'='*80}\n") + except: + pass + frappe.log_error(title="VAT Report: Data Found", message=f"Document: {vat_name}\nCalculated row data:\n{row}") return [row] if row else [get_empty_row(vat_name)]