fix: minor changes

This commit is contained in:
Mangesh-Khairnar 2019-07-22 13:54:39 +05:30
parent 80fb0bf520
commit 29e9f14f95
3 changed files with 14 additions and 5 deletions

View File

@ -357,7 +357,7 @@ class LeaveApplication(Document):
lwp = frappe.db.get_value("Leave Type", self.leave_type, "is_lwp") lwp = frappe.db.get_value("Leave Type", self.leave_type, "is_lwp")
if expiry_date: 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: else:
args = dict( args = dict(
leaves=self.total_leave_days * -1, leaves=self.total_leave_days * -1,
@ -367,16 +367,17 @@ class LeaveApplication(Document):
) )
create_leave_ledger_entry(self, args, submit) 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 ''' ''' splits leave application into two ledger entries to consider expiry of allocation '''
args = dict( args = dict(
from_date=self.from_date, from_date=self.from_date,
to_date=expiry_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) 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) start_date = add_days(expiry_date, 1)
args.update(dict( args.update(dict(
from_date=start_date, from_date=start_date,

View File

@ -9,6 +9,10 @@ from frappe import _
from frappe.utils import add_days, today, flt, DATE_FORMAT from frappe.utils import add_days, today, flt, DATE_FORMAT
class LeaveLedgerEntry(Document): 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): def on_cancel(self):
# allow cancellation of expiry leaves # allow cancellation of expiry leaves
if not self.is_expired: if not self.is_expired:

View File

@ -10,4 +10,8 @@ from frappe import _
from frappe.model.document import Document from frappe.model.document import Document
class LeaveType(Document): class LeaveType(Document):
pass 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