Skip to content

Commit

Permalink
fix: Consider only Approved leave applications in LWP, Employee Benef…
Browse files Browse the repository at this point in the history
…it calculations

- do not allow submitting leave applications with 'Cancelled' status
  • Loading branch information
ruchamahabal committed Jun 7, 2022
1 parent a22d92f commit 7f84c86
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions erpnext/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def on_update(self):
share_doc_with_approver(self, self.leave_approver)

def on_submit(self):
if self.status == "Open":
if self.status in ["Open", "Cancelled"]:
frappe.throw(
_("Only Leave Applications with status 'Approved' and 'Rejected' can be submitted")
)
Expand Down Expand Up @@ -1103,7 +1103,7 @@ def add_leaves(events, start, end, filter_conditions=None):
WHERE
from_date <= %(end)s AND to_date >= %(start)s <= to_date
AND docstatus < 2
AND status != 'Rejected'
AND status in ('Approved', 'Open')
"""

if conditions:
Expand Down Expand Up @@ -1192,6 +1192,7 @@ def get_approved_leaves_for_period(employee, leave_type, from_date, to_date):
from `tabLeave Application`
where employee=%(employee)s
and docstatus=1
and status='Approved'
and (from_date between %(from_date)s and %(to_date)s
or to_date between %(from_date)s and %(to_date)s
or (from_date < %(from_date)s and to_date > %(to_date)s))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ def calculate_lwp(employee, start_date, holidays, working_days):
where t2.name = t1.leave_type
and t2.is_lwp = 1
and t1.docstatus = 1
and t1.status = 'Approved'
and t1.employee = %(employee)s
and CASE WHEN t2.include_holiday != 1 THEN %(dt)s not in ('{0}') and %(dt)s between from_date and to_date
WHEN t2.include_holiday THEN %(dt)s between from_date and to_date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
test_dependencies = ["Holiday List"]


class TestPayrollEntry(unittest.TestCase):
class TestPayrollEntry(FrappeTestCase):
@classmethod
def setUpClass(cls):
frappe.db.set_value(
Expand Down
1 change: 1 addition & 0 deletions erpnext/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,7 @@ def calculate_lwp_or_ppl_based_on_leave_application(self, holidays, working_days
WHERE t2.name = t1.leave_type
AND (t2.is_lwp = 1 or t2.is_ppl = 1)
AND t1.docstatus = 1
AND t1.status = 'Approved'
AND t1.employee = %(employee)s
AND ifnull(t1.salary_slip, '') = ''
AND CASE
Expand Down

0 comments on commit 7f84c86

Please sign in to comment.