fix: minor changes
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 86d9130..8f02ec0 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -357,7 +357,7 @@
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 @@
)
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 a73f10a..99a9d0d 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.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 5b13edb..cbc6781 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.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