mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-06 13:49:13 +00:00
test: update for total leaves allocated post submission
This commit is contained in:
@@ -90,6 +90,7 @@ class LeaveAllocation(Document):
|
|||||||
if self.carry_forward:
|
if self.carry_forward:
|
||||||
self.set_carry_forwarded_leaves_in_previous_allocation(on_cancel=True)
|
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):
|
def on_update_after_submit(self):
|
||||||
if self.has_value_changed("new_leaves_allocated"):
|
if self.has_value_changed("new_leaves_allocated"):
|
||||||
self.validate_against_leave_applications()
|
self.validate_against_leave_applications()
|
||||||
|
|||||||
@@ -356,6 +356,16 @@ class TestLeaveAllocation(FrappeTestCase):
|
|||||||
leave_allocation.new_leaves_allocated = 40
|
leave_allocation.new_leaves_allocated = 40
|
||||||
leave_allocation.save()
|
leave_allocation.save()
|
||||||
leave_allocation.reload()
|
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)
|
self.assertEqual(leave_allocation.total_leaves_allocated, 40)
|
||||||
|
|
||||||
def test_leave_addition_after_submit_with_carry_forward(self):
|
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)
|
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)
|
self.assertEqual(leave_allocation.total_leaves_allocated, 30)
|
||||||
|
|
||||||
leave_allocation.new_leaves_allocated = 32
|
leave_allocation.new_leaves_allocated = 32
|
||||||
@@ -385,6 +395,7 @@ class TestLeaveAllocation(FrappeTestCase):
|
|||||||
limit=1,
|
limit=1,
|
||||||
)
|
)
|
||||||
self.assertEqual(updated_entry[0], 17)
|
self.assertEqual(updated_entry[0], 17)
|
||||||
|
self.assertEqual(leave_allocation.total_leaves_allocated, 47)
|
||||||
|
|
||||||
def test_leave_subtraction_after_submit(self):
|
def test_leave_subtraction_after_submit(self):
|
||||||
leave_allocation = create_leave_allocation(
|
leave_allocation = create_leave_allocation(
|
||||||
@@ -397,6 +408,16 @@ class TestLeaveAllocation(FrappeTestCase):
|
|||||||
leave_allocation.new_leaves_allocated = 10
|
leave_allocation.new_leaves_allocated = 10
|
||||||
leave_allocation.submit()
|
leave_allocation.submit()
|
||||||
leave_allocation.reload()
|
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)
|
self.assertEqual(leave_allocation.total_leaves_allocated, 10)
|
||||||
|
|
||||||
def test_leave_subtraction_after_submit_with_carry_forward(self):
|
def test_leave_subtraction_after_submit_with_carry_forward(self):
|
||||||
@@ -424,6 +445,7 @@ class TestLeaveAllocation(FrappeTestCase):
|
|||||||
limit=1,
|
limit=1,
|
||||||
)
|
)
|
||||||
self.assertEqual(updated_entry[0], -7)
|
self.assertEqual(updated_entry[0], -7)
|
||||||
|
self.assertEqual(leave_allocation.total_leaves_allocated, 23)
|
||||||
|
|
||||||
def test_validation_against_leave_application_after_submit(self):
|
def test_validation_against_leave_application_after_submit(self):
|
||||||
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
|
from erpnext.payroll.doctype.salary_slip.test_salary_slip import make_holiday_list
|
||||||
|
|||||||
Reference in New Issue
Block a user