From 4f8deb92ccb9d00d69901549727d0bedfc87229e Mon Sep 17 00:00:00 2001 From: Jamsheer Date: Mon, 25 Jun 2018 14:49:54 +0530 Subject: [PATCH] [Fix] - Leave Perid - Grant Allocations (#14668) * Leave Perid - Grant Allocations - Fix * Codacy - string statement has no effect --- .../hr/doctype/leave_period/leave_period.py | 27 +++++++++---------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/erpnext/hr/doctype/leave_period/leave_period.py b/erpnext/hr/doctype/leave_period/leave_period.py index bcff89aaa5e..6a8e3bca43f 100644 --- a/erpnext/hr/doctype/leave_period/leave_period.py +++ b/erpnext/hr/doctype/leave_period/leave_period.py @@ -30,9 +30,10 @@ class LeavePeriod(Document): def grant_leave_allocation(self): if self.employee: - leave_allocation = self.grant_leave_alloc(self.employee) + leave_allocation = [] + leave_allocation = self.grant_leave_alloc(self.employee, leave_allocation) if leave_allocation: - self.print_message([leave_allocation]) + self.print_message(leave_allocation) else: self.grant_leave_alloc_for_employees() @@ -41,25 +42,20 @@ class LeavePeriod(Document): if employees: leave_allocations = [] for employee in employees: - leave_allocation = self.grant_leave_alloc(cstr(employee[0])) - if leave_allocation: - leave_allocations.append(leave_allocation) + leave_allocations = self.grant_leave_alloc(cstr(employee[0]), leave_allocations) if leave_allocations: self.print_message(leave_allocations) else: frappe.msgprint(_("No employee found")) - def grant_leave_alloc(self, employee): + def grant_leave_alloc(self, employee, leave_allocations): self.validate_allocation_exists(employee) leave_policy = get_employee_leave_policy(employee) if leave_policy: for leave_policy_detail in leave_policy.leave_policy_details: if not frappe.db.get_value("Leave Type", leave_policy_detail.leave_type, "is_lwp"): - return self.create_leave_allocation(employee, leave_policy_detail.leave_type, leave_policy_detail.annual_allocation) - else: - return None - else: - return None + leave_allocations.append(self.create_leave_allocation(employee, leave_policy_detail.leave_type, leave_policy_detail.annual_allocation)) + return leave_allocations def validate_allocation_exists(self, employee): leave_alloc = frappe.db.exists({ @@ -82,8 +78,11 @@ class LeavePeriod(Document): allocation.leave_type = leave_type allocation.from_date = self.from_date allocation.to_date = self.to_date - '''Earned Leaves are allocated by scheduler, initially allocate 0''' - allocation.new_leaves_allocated = new_leaves_allocated if not frappe.db.get_value("Leave Type", leave_type, "is_earned_leave") else 0 + # Earned Leaves and Compensatory Leaves are allocated by scheduler, initially allocate 0 + is_earned_leave, is_compensatory = frappe.db.get_value("Leave Type", leave_type, ["is_earned_leave", "is_compensatory"]) + if is_earned_leave == 1 or is_compensatory == 1: + new_leaves_allocated = 0 + allocation.new_leaves_allocated = new_leaves_allocated allocation.leave_period = self.name if self.carry_forward_leaves: if frappe.db.get_value("Leave Type", leave_type, "is_carry_forward"): @@ -96,4 +95,4 @@ class LeavePeriod(Document): def print_message(self, leave_allocations): if leave_allocations: frappe.msgprint(_("Leave Allocations {0} created").format(", " - .join(map(lambda x: """ {0}""".format(x), leave_allocations)))) \ No newline at end of file + .join(map(lambda x: """ {0}""".format(x), leave_allocations))))