From 64440fc4fbc55068906af7466aa5b4d5333b9d12 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Tue, 10 May 2022 09:25:32 +0530 Subject: [PATCH] feat(HR): Leave Type configuration to allow over allocation (backport #30940) (#30944) Co-authored-by: Rucha Mahabal --- .../leave_allocation/leave_allocation.py | 13 +++++++++- .../leave_allocation/test_leave_allocation.py | 24 ++++++++++++++++++- erpnext/hr/doctype/leave_type/leave_type.json | 12 +++++++++- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py index 27479a5e81f0..8fae2a9a8886 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py @@ -254,7 +254,18 @@ def validate_total_leaves_allocated(self): # Adding a day to include To Date in the difference date_difference = date_diff(self.to_date, self.from_date) + 1 if date_difference < self.total_leaves_allocated: - frappe.throw(_("Total allocated leaves are more than days in the period"), OverAllocationError) + if frappe.db.get_value("Leave Type", self.leave_type, "allow_over_allocation"): + frappe.msgprint( + _("Total Leaves Allocated are more than the number of days in the allocation period"), + indicator="orange", + alert=True, + ) + else: + frappe.throw( + _("Total Leaves Allocated are more than the number of days in the allocation period"), + exc=OverAllocationError, + title=_("Over Allocation"), + ) def create_leave_ledger_entry(self, submit=True): if self.unused_leaves: diff --git a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py index dde52d7ad8ee..48953003000c 100644 --- a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py @@ -68,22 +68,44 @@ def test_invalid_period(self): self.assertRaises(frappe.ValidationError, doc.save) def test_validation_for_over_allocation(self): + leave_type = create_leave_type(leave_type_name="Test Over Allocation", is_carry_forward=1) + leave_type.save() + doc = frappe.get_doc( { "doctype": "Leave Allocation", "__islocal": 1, "employee": self.employee.name, "employee_name": self.employee.employee_name, - "leave_type": "_Test Leave Type", + "leave_type": leave_type.name, "from_date": getdate("2015-09-1"), "to_date": getdate("2015-09-30"), "new_leaves_allocated": 35, + "carry_forward": 1, } ) # allocated leave more than period self.assertRaises(OverAllocationError, doc.save) + leave_type.allow_over_allocation = 1 + leave_type.save() + + # allows creating a leave allocation with more leave days than period days + doc = frappe.get_doc( + { + "doctype": "Leave Allocation", + "__islocal": 1, + "employee": self.employee.name, + "employee_name": self.employee.employee_name, + "leave_type": leave_type.name, + "from_date": getdate("2015-09-1"), + "to_date": getdate("2015-09-30"), + "new_leaves_allocated": 35, + "carry_forward": 1, + } + ).insert() + def test_validation_for_over_allocation_post_submission(self): allocation = frappe.get_doc( { diff --git a/erpnext/hr/doctype/leave_type/leave_type.json b/erpnext/hr/doctype/leave_type/leave_type.json index 06ca4cdedbcc..d40ff09619dc 100644 --- a/erpnext/hr/doctype/leave_type/leave_type.json +++ b/erpnext/hr/doctype/leave_type/leave_type.json @@ -19,6 +19,7 @@ "fraction_of_daily_salary_per_leave", "is_optional_leave", "allow_negative", + "allow_over_allocation", "include_holiday", "is_compensatory", "carry_forward_section", @@ -211,15 +212,23 @@ "fieldtype": "Float", "label": "Fraction of Daily Salary per Leave", "mandatory_depends_on": "eval:doc.is_ppl == 1" + }, + { + "default": "0", + "description": "Allows allocating more leaves than the number of days in the allocation period.", + "fieldname": "allow_over_allocation", + "fieldtype": "Check", + "label": "Allow Over Allocation" } ], "icon": "fa fa-flag", "idx": 1, "links": [], - "modified": "2021-10-02 11:59:40.503359", + "modified": "2022-05-09 05:01:38.957545", "modified_by": "Administrator", "module": "HR", "name": "Leave Type", + "naming_rule": "By fieldname", "owner": "Administrator", "permissions": [ { @@ -251,5 +260,6 @@ ], "sort_field": "modified", "sort_order": "DESC", + "states": [], "track_changes": 1 } \ No newline at end of file