From 1544253f99c82acbbc714b487d9c7cb7f164d059 Mon Sep 17 00:00:00 2001 From: Ali <010109ali@gmail.com> Date: Fri, 6 Feb 2026 15:13:55 +0400 Subject: [PATCH] fixed vat allocation total fields --- .../doctype/vat_allocation/vat_allocation.py | 41 +++++++++++++++++-- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py b/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py index c8fa3ec..a9ce403 100644 --- a/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py +++ b/taxes_az/taxes_az/doctype/vat_allocation/vat_allocation.py @@ -11,8 +11,8 @@ class VATallocation(Document): def validate(self): # Check if document with same year and month already exists self.validate_unique_year_month() - # Recalculate all totals from links - #self.recalculate_totals_from_links() + # Calculate totals by tax template (without modifying child tables) + self.calculate_tax_template_totals() # Validate all allocations self.validate_allocations() @@ -100,7 +100,42 @@ class VATallocation(Document): total = Decimal(str(si_row.amount or 0)) allocated = Decimal(str(si_row.allocated_amount or 0)) si_row.unallocated_amount = float(max(Decimal('0'), total - allocated)) - + + # Calculate totals by tax template + self.calculate_tax_template_totals() + + def calculate_tax_template_totals(self): + """ + Calculate totals by tax template from sales invoice table + """ + # Reset totals + self.total_edv_daxil_18 = 0 + self.total_edv_azadolma = 0 + self.total_edv_0 = 0 + self.total_edv_18 = 0 + self.total_allocated_sum = 0 + + # Calculate totals - only from current month table + for si_row in self.sales_invoice_table: + allocated = Decimal(str(si_row.allocated_amount or 0)) + if allocated <= 0: + continue + + template = (si_row.item_tax_template or '').strip() + + # Match by template name + if template == 'ƏDV daxil 18%': + self.total_edv_daxil_18 = float(Decimal(str(self.total_edv_daxil_18 or 0)) + allocated) + elif template == 'ƏDV-dən azadolma': + self.total_edv_azadolma = float(Decimal(str(self.total_edv_azadolma or 0)) + allocated) + elif template == 'ƏDV 0%': + self.total_edv_0 = float(Decimal(str(self.total_edv_0 or 0)) + allocated) + elif template == 'ƏDV 18%': + self.total_edv_18 = float(Decimal(str(self.total_edv_18 or 0)) + allocated) + + # Add to total sum + self.total_allocated_sum = float(Decimal(str(self.total_allocated_sum or 0)) + allocated) + def validate_allocations(self): """ Validate that all allocations are mathematically correct