fixed vat allocation total fields

This commit is contained in:
Ali 2026-02-06 15:13:55 +04:00
parent b34621319c
commit 1544253f99
1 changed files with 38 additions and 3 deletions

View File

@ -11,8 +11,8 @@ class VATallocation(Document):
def validate(self): def validate(self):
# Check if document with same year and month already exists # Check if document with same year and month already exists
self.validate_unique_year_month() self.validate_unique_year_month()
# Recalculate all totals from links # Calculate totals by tax template (without modifying child tables)
#self.recalculate_totals_from_links() self.calculate_tax_template_totals()
# Validate all allocations # Validate all allocations
self.validate_allocations() self.validate_allocations()
@ -100,7 +100,42 @@ class VATallocation(Document):
total = Decimal(str(si_row.amount or 0)) total = Decimal(str(si_row.amount or 0))
allocated = Decimal(str(si_row.allocated_amount or 0)) allocated = Decimal(str(si_row.allocated_amount or 0))
si_row.unallocated_amount = float(max(Decimal('0'), total - allocated)) 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): def validate_allocations(self):
""" """
Validate that all allocations are mathematically correct Validate that all allocations are mathematically correct