From 2b65c9616ff81ac8e8a1d6352965adbbd5b7a21e Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Wed, 11 May 2022 16:43:13 +0530 Subject: [PATCH] fix: component pay calculation --- .../salary_structure/salary_structure.py | 4 ++++ erpnext/regional/india/utils.py | 20 +++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/erpnext/payroll/doctype/salary_structure/salary_structure.py b/erpnext/payroll/doctype/salary_structure/salary_structure.py index fa36b7ab2d..edf17dbfb1 100644 --- a/erpnext/payroll/doctype/salary_structure/salary_structure.py +++ b/erpnext/payroll/doctype/salary_structure/salary_structure.py @@ -253,6 +253,7 @@ def make_salary_slip( source_name, target_doc=None, employee=None, + posting_date=None, as_print=False, print_format=None, for_preview=0, @@ -269,6 +270,9 @@ def make_salary_slip( target.designation = employee_details.designation target.department = employee_details.department + if posting_date: + target.posting_date = posting_date + target.run_method("process_salary_structure", for_preview=for_preview) doc = get_mapped_doc( diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py index 6aa1f1f277..2fc1565361 100644 --- a/erpnext/regional/india/utils.py +++ b/erpnext/regional/india/utils.py @@ -422,8 +422,8 @@ def calculate_annual_eligible_hra_exemption(doc): return frappe._dict( { "hra_amount": hra_amount, - "annual_exemption": annual_exemption, - "monthly_exemption": monthly_exemption, + "annual_exemption": flt(annual_exemption, doc.precision("annual_hra_exemption")), + "monthly_exemption": flt(monthly_exemption, doc.precision("monthly_hra_exemption")), } ) @@ -459,12 +459,12 @@ def get_component_amt_from_salary_slip( employee, salary_structure, basic_component, hra_component, from_date ): salary_slip = make_salary_slip( - salary_structure, employee=employee, for_preview=1, ignore_permissions=True + salary_structure, + employee=employee, + for_preview=1, + ignore_permissions=True, + posting_date=from_date, ) - # generate salary slip as per assignment on "from_date" - salary_slip.posting_date = from_date - salary_slip.start_date = salary_slip.end_date = None - salary_slip.run_method("process_salary_structure", for_preview=True) basic_amt, hra_amt = 0, 0 for earning in salary_slip.earnings: @@ -502,13 +502,13 @@ def get_component_pay(frequency, amount, from_date, to_date): if frequency == "Daily": return amount * days elif frequency == "Weekly": - return amount * math.ceil(days / 7) + return amount * math.floor(days / 7) elif frequency == "Fortnightly": - return amount * math.ceil(days / 15) + return amount * math.floor(days / 14) elif frequency == "Monthly": return amount * month_diff(to_date, from_date) elif frequency == "Bimonthly": - return amount * math.ceil(days / 60) + return amount * (month_diff(to_date, from_date) / 2) def validate_house_rent_dates(doc):