feat(single-declaration): fill vergi məbləği in əlavə 1 hissə 1

Per-employee quarterly income tax: brackets applied to each month's
gross pay, then summed for the quarter. Reuses the same per-month
gross helper as bölmə 3.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Ali 2026-05-05 17:14:37 +00:00
parent 2e15e9dae4
commit caedd576b1
1 changed files with 20 additions and 10 deletions

View File

@ -93,11 +93,12 @@ def populate_declaration_tables(company, year, quarter):
# Fetch payroll data once, build hissə_1 and hissə_2 from it
payroll = fetch_payroll_data(company, from_date, to_date)
hisse_1_data = build_hisse_1(payroll)
emp_monthly_gross = _per_employee_monthly_gross(payroll, quarter)
hisse_1_data = build_hisse_1(payroll, emp_monthly_gross)
hisse_2_data = build_hisse_2(payroll)
hisse_3_data = get_absence_data(company, from_date, to_date)
bolme2_hisse1_data = get_bolme2_hisse1_data(company, year, quarter)
bolme_3_data = build_bolme_3(payroll, quarter)
bolme_3_data = build_bolme_3(emp_monthly_gross)
elave4_data = build_elave4_tables(payroll)
return {
@ -201,18 +202,23 @@ def fetch_payroll_data(company, from_date, to_date):
}
def build_hisse_1(payroll):
def build_hisse_1(payroll, emp_monthly_gross):
"""Build hissə_1 rows from aggregated payroll data."""
employee_map = payroll["employee_map"]
fin_map = payroll["fin_map"]
emp_quarterly_tax = {}
for (emp, _mi), gross in emp_monthly_gross.items():
emp_quarterly_tax[emp] = emp_quarterly_tax.get(emp, 0.0) + _calc_income_tax(gross)
result = []
for agg in employee_map.values():
emp = agg["employee"]
child_row = {
"soyadadataadı": agg["employee_name"],
"fin": fin_map.get(agg["employee"], ""),
"fin": fin_map.get(emp, ""),
"gəlirlərcəmi": agg.get(frappe.scrub("Əsas əmək haqqı"), 0),
# vergiməbləği intentionally not filled
"vergiməbləği": round(emp_quarterly_tax.get(emp, 0.0), 2),
"hesablanmışmdsshaqqı": flt(agg.get(_DSMF_ISCI, 0)) + flt(agg.get(_DSMF_SIRKET, 0)),
"hesablanmışişsizlikdənsığortahaqqı": flt(agg.get(_ISSIZLIK_ISCI, 0)) + flt(agg.get(_ISSIZLIK_SIRKET, 0)),
"hesablanmışicbaritibbisığortahaqqı": flt(agg.get(_ITS_ISCI, 0)) + flt(agg.get(_ITS_SIRKET, 0)),
@ -299,8 +305,8 @@ def _calc_income_tax(gross):
return 625 + (gross - 8000) * 0.14
def build_bolme_3(payroll, quarter):
"""Income tax (gəlir vergisi) per month, computed per-employee then summed."""
def _per_employee_monthly_gross(payroll, quarter):
"""Group salary slips into {(employee, month_index_1to3): gross_pay_sum}."""
salary_slips = payroll["salary_slips"]
currency = payroll["currency"]
company_currency = payroll["company_currency"]
@ -308,7 +314,7 @@ def build_bolme_3(payroll, quarter):
quarter_num = int(quarter[0])
start_month = (quarter_num - 1) * 3 + 1
per_emp_monthly_gross = {}
result = {}
for ss in salary_slips:
month_index = ss.start_date.month - start_month + 1
if month_index not in (1, 2, 3):
@ -317,10 +323,14 @@ def build_bolme_3(payroll, quarter):
if currency == company_currency:
gp *= flt(ss.exchange_rate)
key = (ss.employee, month_index)
per_emp_monthly_gross[key] = per_emp_monthly_gross.get(key, 0.0) + gp
result[key] = result.get(key, 0.0) + gp
return result
def build_bolme_3(emp_monthly_gross):
"""Income tax (gəlir vergisi) per month, computed per-employee then summed."""
monthly_tax = {1: 0.0, 2: 0.0, 3: 0.0}
for (_emp, mi), gross in per_emp_monthly_gross.items():
for (_emp, mi), gross in emp_monthly_gross.items():
monthly_tax[mi] += _calc_income_tax(gross)
return {