From c1de4e44207d391237f593c9b81bf0e1de2320f6 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Mon, 13 Feb 2023 18:51:53 +0530 Subject: [PATCH 1/2] fix: LWP calculation --- erpnext/payroll/doctype/salary_slip/salary_slip.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 0563541eaa5..995f4dc0022 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -1,7 +1,6 @@ # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # License: GNU General Public License v3. See license.txt - import datetime import math @@ -316,6 +315,8 @@ class SalarySlip(TransactionBase): ) working_days = date_diff(self.end_date, self.start_date) + 1 + working_days_list = [add_days(self.start_date, i) for i in range(working_days)] + if for_preview: self.total_working_days = working_days self.payment_days = working_days @@ -335,7 +336,7 @@ class SalarySlip(TransactionBase): actual_lwp, absent = self.calculate_lwp_ppl_and_absent_days_based_on_attendance(holidays) self.absent_days = absent else: - actual_lwp = self.calculate_lwp_or_ppl_based_on_leave_application(holidays, working_days) + actual_lwp = self.calculate_lwp_or_ppl_based_on_leave_application(holidays, working_days_list) if not lwp: lwp = actual_lwp @@ -458,16 +459,15 @@ class SalarySlip(TransactionBase): def get_holidays_for_employee(self, start_date, end_date): return get_holiday_dates_for_employee(self.employee, start_date, end_date) - def calculate_lwp_or_ppl_based_on_leave_application(self, holidays, working_days): + def calculate_lwp_or_ppl_based_on_leave_application(self, holidays, working_days_list): lwp = 0 - holidays = "','".join(holidays) + daily_wages_fraction_for_half_day = ( flt(frappe.db.get_value("Payroll Settings", None, "daily_wages_fraction_for_half_day")) or 0.5 ) - for d in range(working_days): - date = add_days(cstr(getdate(self.start_date)), d) - leave = get_lwp_or_ppl_for_date(date, self.employee, holidays) + for d in working_days_list: + leave = get_lwp_or_ppl_for_date(d, self.employee, holidays) if leave: equivalent_lwp_count = 0 From a8ea3efae29200d470435dc665ca00899b356d76 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Tue, 14 Feb 2023 13:14:58 +0530 Subject: [PATCH 2/2] fix: validate working day list against holidays --- erpnext/payroll/doctype/salary_slip/salary_slip.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/erpnext/payroll/doctype/salary_slip/salary_slip.py b/erpnext/payroll/doctype/salary_slip/salary_slip.py index 995f4dc0022..302c0d2853a 100644 --- a/erpnext/payroll/doctype/salary_slip/salary_slip.py +++ b/erpnext/payroll/doctype/salary_slip/salary_slip.py @@ -326,6 +326,8 @@ class SalarySlip(TransactionBase): if not cint(include_holidays_in_total_working_days): working_days -= len(holidays) + working_days_list = [cstr(day) for day in working_days_list if cstr(day) not in holidays] + if working_days < 0: frappe.throw(_("There are more holidays than working days this month."))