[fix] Set payment days considering joinging date, reliving date and applicable holidays
This commit is contained in:
parent
c4d9554a05
commit
a4eeb919e6
@ -7,6 +7,10 @@
|
|||||||
"description": "New Year",
|
"description": "New Year",
|
||||||
"holiday_date": "2013-01-01"
|
"holiday_date": "2013-01-01"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"description": "Republic Day",
|
||||||
|
"holiday_date": "2013-01-26"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"description": "Test Holiday",
|
"description": "Test Holiday",
|
||||||
"holiday_date": "2013-02-01"
|
"holiday_date": "2013-02-01"
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
|
|
||||||
from frappe.utils import add_days, cint, cstr, flt, getdate, nowdate, rounded
|
from frappe.utils import add_days, cint, cstr, flt, getdate, nowdate, rounded, date_diff
|
||||||
from frappe.model.naming import make_autoname
|
from frappe.model.naming import make_autoname
|
||||||
|
|
||||||
from frappe import msgprint, _
|
from frappe import msgprint, _
|
||||||
@ -68,46 +68,46 @@ class SalarySlip(TransactionBase):
|
|||||||
["date_of_joining", "relieving_date"])
|
["date_of_joining", "relieving_date"])
|
||||||
|
|
||||||
m = get_month_details(self.fiscal_year, self.month)
|
m = get_month_details(self.fiscal_year, self.month)
|
||||||
holidays = self.get_holidays_for_employee(m, joining_date, relieving_date)
|
holidays = self.get_holidays_for_employee(m['month_start_date'], m['month_end_date'])
|
||||||
|
|
||||||
if not cint(frappe.db.get_value("HR Settings", "HR Settings",
|
working_days = m["month_days"]
|
||||||
"include_holidays_in_total_working_days")):
|
if not cint(frappe.db.get_value("HR Settings", None, "include_holidays_in_total_working_days")):
|
||||||
m["month_days"] -= len(holidays)
|
working_days -= len(holidays)
|
||||||
if m["month_days"] < 0:
|
if working_days < 0:
|
||||||
frappe.throw(_("There are more holidays than working days this month."))
|
frappe.throw(_("There are more holidays than working days this month."))
|
||||||
|
|
||||||
if not lwp:
|
if not lwp:
|
||||||
lwp = self.calculate_lwp(holidays, m)
|
lwp = self.calculate_lwp(holidays, m)
|
||||||
self.total_days_in_month = m['month_days']
|
self.total_days_in_month = working_days
|
||||||
self.leave_without_pay = lwp
|
self.leave_without_pay = lwp
|
||||||
payment_days = flt(self.get_payment_days(m, joining_date, relieving_date)) - flt(lwp)
|
payment_days = flt(self.get_payment_days(m, joining_date, relieving_date)) - flt(lwp)
|
||||||
self.payment_days = payment_days > 0 and payment_days or 0
|
self.payment_days = payment_days > 0 and payment_days or 0
|
||||||
|
|
||||||
def get_payment_days(self, m, joining_date, relieving_date):
|
def get_payment_days(self, month, joining_date, relieving_date):
|
||||||
payment_days = m['month_days']
|
start_date = month['month_start_date']
|
||||||
if relieving_date:
|
|
||||||
if getdate(relieving_date) > m['month_start_date'] \
|
|
||||||
and getdate(relieving_date) < m['month_end_date']:
|
|
||||||
payment_days = getdate(relieving_date).day
|
|
||||||
elif getdate(relieving_date) < m['month_start_date']:
|
|
||||||
frappe.throw(_("Employee relieved on {0} must be set as 'Left'").format(relieving_date))
|
|
||||||
|
|
||||||
if joining_date:
|
if joining_date:
|
||||||
if getdate(joining_date) > m['month_start_date'] and \
|
if joining_date > month['month_start_date']:
|
||||||
getdate(joining_date) < m['month_end_date']:
|
start_date = joining_date
|
||||||
payment_days = payment_days - getdate(joining_date).day + 1
|
elif joining_date > month['month_end_date']:
|
||||||
elif getdate(joining_date) > m['month_end_date']:
|
return
|
||||||
payment_days = 0
|
|
||||||
|
if relieving_date:
|
||||||
|
if relieving_date > start_date and relieving_date < month['month_end_date']:
|
||||||
|
end_date = relieving_date
|
||||||
|
elif relieving_date < month['month_start_date']:
|
||||||
|
frappe.throw(_("Employee relieved on {0} must be set as 'Left'").format(relieving_date))
|
||||||
|
else:
|
||||||
|
end_date = month['month_end_date']
|
||||||
|
|
||||||
|
payment_days = date_diff(end_date, start_date) + 1
|
||||||
|
|
||||||
|
if not cint(frappe.db.get_value("HR Settings", None, "include_holidays_in_total_working_days")):
|
||||||
|
holidays = self.get_holidays_for_employee(start_date, end_date)
|
||||||
|
payment_days -= len(holidays)
|
||||||
|
|
||||||
return payment_days
|
return payment_days
|
||||||
|
|
||||||
def get_holidays_for_employee(self, month, joining_date, relieving_date):
|
def get_holidays_for_employee(self, start_date, end_date):
|
||||||
start_date = month['month_start_date'] \
|
|
||||||
if joining_date < month['month_start_date'] else joining_date
|
|
||||||
|
|
||||||
end_date = relieving_date \
|
|
||||||
if (relieving_date and relieving_date < month['month_end_date']) else month['month_end_date']
|
|
||||||
|
|
||||||
holidays = frappe.db.sql("""select t1.holiday_date
|
holidays = frappe.db.sql("""select t1.holiday_date
|
||||||
from `tabHoliday` t1, tabEmployee t2
|
from `tabHoliday` t1, tabEmployee t2
|
||||||
where t1.parent = t2.holiday_list and t2.name = %s
|
where t1.parent = t2.holiday_list and t2.name = %s
|
||||||
@ -159,7 +159,7 @@ class SalarySlip(TransactionBase):
|
|||||||
if not (len(self.get("earnings")) or len(self.get("deductions"))):
|
if not (len(self.get("earnings")) or len(self.get("deductions"))):
|
||||||
self.get_emp_and_leave_details()
|
self.get_emp_and_leave_details()
|
||||||
else:
|
else:
|
||||||
self.get_leave_details(self.leave_without_pay)
|
self.get_leave_details(lwp = self.leave_without_pay)
|
||||||
|
|
||||||
if not self.net_pay:
|
if not self.net_pay:
|
||||||
self.calculate_net_pay()
|
self.calculate_net_pay()
|
||||||
|
@ -25,11 +25,11 @@ class TestSalarySlip(unittest.TestCase):
|
|||||||
la.submit()
|
la.submit()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 0)
|
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
|
||||||
frappe.set_user("Administrator")
|
frappe.set_user("Administrator")
|
||||||
|
|
||||||
def test_salary_slip_with_holidays_included(self):
|
def test_salary_slip_with_holidays_included(self):
|
||||||
frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 1)
|
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
|
||||||
ss = frappe.copy_doc(test_records[0])
|
ss = frappe.copy_doc(test_records[0])
|
||||||
ss.insert()
|
ss.insert()
|
||||||
|
|
||||||
@ -43,18 +43,46 @@ class TestSalarySlip(unittest.TestCase):
|
|||||||
self.assertEquals(ss.net_pay, 14867.74)
|
self.assertEquals(ss.net_pay, 14867.74)
|
||||||
|
|
||||||
def test_salary_slip_with_holidays_excluded(self):
|
def test_salary_slip_with_holidays_excluded(self):
|
||||||
frappe.db.set_value("HR Settings", "HR Settings", "include_holidays_in_total_working_days", 0)
|
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
|
||||||
ss = frappe.copy_doc(test_records[0])
|
ss = frappe.copy_doc(test_records[0])
|
||||||
ss.insert()
|
ss.insert()
|
||||||
|
|
||||||
self.assertEquals(ss.total_days_in_month, 30)
|
self.assertEquals(ss.total_days_in_month, 29)
|
||||||
self.assertEquals(ss.payment_days, 29)
|
self.assertEquals(ss.payment_days, 28)
|
||||||
self.assertEquals(ss.earnings[0].e_modified_amount, 14500)
|
self.assertEquals(ss.earnings[0].e_modified_amount, 14482.76)
|
||||||
self.assertEquals(ss.earnings[1].e_modified_amount, 500)
|
self.assertEquals(ss.earnings[1].e_modified_amount, 500)
|
||||||
self.assertEquals(ss.deductions[0].d_modified_amount, 100)
|
self.assertEquals(ss.deductions[0].d_modified_amount, 100)
|
||||||
self.assertEquals(ss.deductions[1].d_modified_amount, 48.33)
|
self.assertEquals(ss.deductions[1].d_modified_amount, 48.28)
|
||||||
self.assertEquals(ss.gross_pay, 15000)
|
self.assertEquals(ss.gross_pay, 14982.76)
|
||||||
self.assertEquals(ss.net_pay, 14851.67)
|
self.assertEquals(ss.net_pay, 14834.48)
|
||||||
|
|
||||||
|
def test_payment_days(self):
|
||||||
|
# Holidays not included in working days
|
||||||
|
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
|
||||||
|
|
||||||
|
# set joinng date in the same month
|
||||||
|
frappe.db.set_value("Employee", "_T-Employee-0001", "date_of_joining", "2013-01-11")
|
||||||
|
|
||||||
|
ss = frappe.copy_doc(test_records[0])
|
||||||
|
ss.insert()
|
||||||
|
|
||||||
|
self.assertEquals(ss.total_days_in_month, 29)
|
||||||
|
self.assertEquals(ss.payment_days, 19)
|
||||||
|
|
||||||
|
# set relieving date in the same month
|
||||||
|
frappe.db.set_value("Employee", "_T-Employee-0001", "relieving_date", "2013-01-28")
|
||||||
|
ss.save()
|
||||||
|
self.assertEquals(ss.total_days_in_month, 29)
|
||||||
|
self.assertEquals(ss.payment_days, 16)
|
||||||
|
|
||||||
|
# Holidays included in working days
|
||||||
|
frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 1)
|
||||||
|
ss.save()
|
||||||
|
self.assertEquals(ss.total_days_in_month, 31)
|
||||||
|
self.assertEquals(ss.payment_days, 17)
|
||||||
|
|
||||||
|
frappe.db.set_value("Employee", "_T-Employee-0001", "date_of_joining", "2001-01-11")
|
||||||
|
frappe.db.set_value("Employee", "_T-Employee-0001", "relieving_date", None)
|
||||||
|
|
||||||
def test_employee_salary_slip_read_permission(self):
|
def test_employee_salary_slip_read_permission(self):
|
||||||
self.make_employee("test_employee@example.com")
|
self.make_employee("test_employee@example.com")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user