Merge pull request #34041 from saurabh6790/fix-lwp-calculations
fix: LWP calculation
This commit is contained in:
@@ -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
|
||||
@@ -325,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."))
|
||||
|
||||
@@ -335,7 +338,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 +461,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
|
||||
|
||||
Reference in New Issue
Block a user