diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py index 6f289b405f3..09484d33755 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py @@ -90,6 +90,7 @@ class LeaveAllocation(Document): if self.carry_forward: self.set_carry_forwarded_leaves_in_previous_allocation(on_cancel=True) + # nosemgrep: frappe-semgrep-rules.rules.frappe-modifying-but-not-comitting def on_update_after_submit(self): if self.has_value_changed("new_leaves_allocated"): self.validate_against_leave_applications() diff --git a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py index d9482a596cd..3a234b6fa97 100644 --- a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py @@ -356,6 +356,16 @@ class TestLeaveAllocation(FrappeTestCase): leave_allocation.new_leaves_allocated = 40 leave_allocation.save() leave_allocation.reload() + + updated_entry = frappe.db.get_all( + "Leave Ledger Entry", + {"transaction_name": leave_allocation.name}, + pluck="leaves", + order_by="creation desc", + limit=1, + ) + + self.assertEqual(updated_entry[0], 25) self.assertEqual(leave_allocation.total_leaves_allocated, 40) def test_leave_addition_after_submit_with_carry_forward(self): @@ -370,7 +380,7 @@ class TestLeaveAllocation(FrappeTestCase): ) leave_allocation = create_carry_forwarded_allocation(self.employee, leave_type) - + # 15 new leaves, 15 carry forwarded leaves self.assertEqual(leave_allocation.total_leaves_allocated, 30) leave_allocation.new_leaves_allocated = 32 @@ -385,6 +395,7 @@ class TestLeaveAllocation(FrappeTestCase): limit=1, ) self.assertEqual(updated_entry[0], 17) + self.assertEqual(leave_allocation.total_leaves_allocated, 47) def test_leave_subtraction_after_submit(self): leave_allocation = create_leave_allocation( @@ -397,6 +408,16 @@ class TestLeaveAllocation(FrappeTestCase): leave_allocation.new_leaves_allocated = 10 leave_allocation.submit() leave_allocation.reload() + + updated_entry = frappe.db.get_all( + "Leave Ledger Entry", + {"transaction_name": leave_allocation.name}, + pluck="leaves", + order_by="creation desc", + limit=1, + ) + + self.assertEqual(updated_entry[0], -5) self.assertEqual(leave_allocation.total_leaves_allocated, 10) def test_leave_subtraction_after_submit_with_carry_forward(self): @@ -424,6 +445,7 @@ class TestLeaveAllocation(FrappeTestCase): limit=1, ) self.assertEqual(updated_entry[0], -7) + self.assertEqual(leave_allocation.total_leaves_allocated, 23) def test_validation_against_leave_application_after_submit(self): from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list