fixed report vat allocation

This commit is contained in:
Ali 2026-02-09 19:55:18 +04:00
parent b848bbd1d0
commit 4d778cf8f1
2 changed files with 19 additions and 10 deletions

View File

@ -168,7 +168,7 @@
"fieldname": "sales_invoice_previous_table", "fieldname": "sales_invoice_previous_table",
"fieldtype": "Table", "fieldtype": "Table",
"label": "Sales Invoice Previous Months", "label": "Sales Invoice Previous Months",
"options": "VAT allocation sales invoice previous months" "options": "VAT allocation sales invoice"
}, },
{ {
"fieldname": "column_break_lpuu", "fieldname": "column_break_lpuu",

View File

@ -91,8 +91,9 @@ def calculate_row_data(vat_allocation_name):
item_tax_template, item_tax_template,
SUM(amount) as total_amount, SUM(amount) as total_amount,
SUM(allocated_amount) as total_allocated SUM(allocated_amount) as total_allocated
FROM `tabVAT allocation sales invoice previous months` FROM `tabVAT allocation sales invoice`
WHERE parent = %(parent)s WHERE parent = %(parent)s
AND parentfield = 'sales_invoice_previous_table'
GROUP BY item_tax_template GROUP BY item_tax_template
""", {"parent": vat_allocation_name}, as_dict=1) """, {"parent": vat_allocation_name}, as_dict=1)
@ -103,9 +104,15 @@ def calculate_row_data(vat_allocation_name):
SUM(unallocated_amount) as total_unallocated SUM(unallocated_amount) as total_unallocated
FROM `tabVAT allocation sales invoice` FROM `tabVAT allocation sales invoice`
WHERE parent = %(parent)s WHERE parent = %(parent)s
AND parentfield = 'sales_invoice_table'
GROUP BY item_tax_template GROUP BY item_tax_template
""", {"parent": vat_allocation_name}, as_dict=1) """, {"parent": vat_allocation_name}, as_dict=1)
# Debug: log the raw data
frappe.logger().debug(f"VAT Allocation: {vat_allocation_name}")
frappe.logger().debug(f"Previous month data: {prev_month_data}")
frappe.logger().debug(f"Current month data: {current_month_data}")
# Initialize row # Initialize row
row = { row = {
'vat_allocation': vat_allocation_name, 'vat_allocation': vat_allocation_name,
@ -122,30 +129,32 @@ def calculate_row_data(vat_allocation_name):
# Process previous month data # Process previous month data
for item in prev_month_data: for item in prev_month_data:
template = (item.item_tax_template or '').strip() template = (item.item_tax_template or '').strip().lower()
amount = flt(item.total_amount) amount = flt(item.total_amount)
allocated = flt(item.total_allocated) allocated = flt(item.total_allocated)
if template in ['ƏDV 18%', 'ƏDV daxil 18%']: # Match templates (case-insensitive)
if 'ədv 18%' in template or 'ədv daxil 18%' in template:
row['prev_month_18'] += amount row['prev_month_18'] += amount
row['allocated_18'] += allocated row['allocated_18'] += allocated
elif template == 'ƏDV 0%': elif 'ədv 0%' in template:
row['prev_month_0'] += amount row['prev_month_0'] += amount
row['allocated_0'] += allocated row['allocated_0'] += allocated
elif template == 'ƏDV-dən azadolma': elif 'azadolma' in template:
row['prev_month_azad'] += amount row['prev_month_azad'] += amount
row['allocated_azad'] += allocated row['allocated_azad'] += allocated
# Process current month data # Process current month data
for item in current_month_data: for item in current_month_data:
template = (item.item_tax_template or '').strip() template = (item.item_tax_template or '').strip().lower()
unallocated = flt(item.total_unallocated) unallocated = flt(item.total_unallocated)
if template in ['ƏDV 18%', 'ƏDV daxil 18%']: # Match templates (case-insensitive)
if 'ədv 18%' in template or 'ədv daxil 18%' in template:
row['unallocated_18'] += unallocated row['unallocated_18'] += unallocated
elif template == 'ƏDV 0%': elif 'ədv 0%' in template:
row['unallocated_0'] += unallocated row['unallocated_0'] += unallocated
elif template == 'ƏDV-dən azadolma': elif 'azadolma' in template:
row['unallocated_azad'] += unallocated row['unallocated_azad'] += unallocated
# Calculate balances # Calculate balances