From 29e9f14f95e967141841c3519946d5b3b7dae7c2 Mon Sep 17 00:00:00 2001 From: Mangesh-Khairnar Date: Mon, 22 Jul 2019 13:54:39 +0530 Subject: [PATCH] fix: minor changes --- .../hr/doctype/leave_application/leave_application.py | 9 +++++---- .../hr/doctype/leave_ledger_entry/leave_ledger_entry.py | 4 ++++ erpnext/hr/doctype/leave_type/leave_type.py | 6 +++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 86d9130aab..8f02ec0f92 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -357,7 +357,7 @@ class LeaveApplication(Document): lwp = frappe.db.get_value("Leave Type", self.leave_type, "is_lwp") if expiry_date: - self.create_ledger_entry_for_intermediate_allocation_expiry(expiry_date, submit) + self.create_ledger_entry_for_intermediate_allocation_expiry(expiry_date, submit, lwp) else: args = dict( leaves=self.total_leave_days * -1, @@ -367,16 +367,17 @@ class LeaveApplication(Document): ) create_leave_ledger_entry(self, args, submit) - def create_ledger_entry_for_intermediate_allocation_expiry(self, expiry_date, submit): + def create_ledger_entry_for_intermediate_allocation_expiry(self, expiry_date, submit, lwp): ''' splits leave application into two ledger entries to consider expiry of allocation ''' args = dict( from_date=self.from_date, to_date=expiry_date, - leaves=(date_diff(expiry_date, self.from_date) + 1) * -1 + leaves=(date_diff(expiry_date, self.from_date) + 1) * -1, + is_lwp=lwp ) create_leave_ledger_entry(self, args, submit) - if expiry_date != self.to_date: + if getdate(expiry_date) != getdate(self.to_date): start_date = add_days(expiry_date, 1) args.update(dict( from_date=start_date, diff --git a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py index a73f10adb8..99a9d0d933 100644 --- a/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py +++ b/erpnext/hr/doctype/leave_ledger_entry/leave_ledger_entry.py @@ -9,6 +9,10 @@ from frappe import _ from frappe.utils import add_days, today, flt, DATE_FORMAT class LeaveLedgerEntry(Document): + def validate(self): + if self.from_date > self.to_date: + frappe.throw(_("To date needs to be before from date")) + def on_cancel(self): # allow cancellation of expiry leaves if not self.is_expired: diff --git a/erpnext/hr/doctype/leave_type/leave_type.py b/erpnext/hr/doctype/leave_type/leave_type.py index 5b13edb684..cbc6781783 100644 --- a/erpnext/hr/doctype/leave_type/leave_type.py +++ b/erpnext/hr/doctype/leave_type/leave_type.py @@ -10,4 +10,8 @@ from frappe import _ from frappe.model.document import Document class LeaveType(Document): - pass \ No newline at end of file + def validate(self): + if self.is_lwp: + leave_allocation = frappe.get_doc("Leave Allocation", {"leave_type": self.name}, ['name']) + if leave_allocation: + frappe.throw(_("""Leave application is linked with leave allocations {0}. Leave application cannot be set as leave without pay""").format(", ".join(leave_allocation))) #nosec \ No newline at end of file