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 9ab9499..70c590a 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 @@ -85,13 +85,27 @@ def get_data(filters): # Validate filters - return empty row if incomplete if not filters.get('company'): return [get_empty_row()] - if not filters.get('year'): - return [get_empty_row()] - if not filters.get('month'): - return [get_empty_row()] + + # Support both direct year/month filters AND from_date/to_date (for Formula Editor) + year = filters.get('year') + month = filters.get('month') + + # If year/month not provided, try to extract from from_date or to_date + if not year or not month: + date_to_use = filters.get('to_date') or filters.get('from_date') + if date_to_use: + from frappe.utils import getdate + date_obj = getdate(date_to_use) + year = date_obj.year + # Convert month number to month name + month_names = ['January', 'February', 'March', 'April', 'May', 'June', + 'July', 'August', 'September', 'October', 'November', 'December'] + month = month_names[date_obj.month - 1] + else: + return [get_empty_row()] # Find VAT allocation document (max one result due to autoname format) - vat_name = f"VAT-{filters.get('year')}-{filters.get('month')}" + vat_name = f"VAT-{year}-{month}" if not frappe.db.exists("VAT allocation", vat_name): return [get_empty_row(vat_name)]