fix: check for old unexpired allocation

This commit is contained in:
Mangesh-Khairnar 2019-08-05 15:35:19 +05:30
parent 6bed870dfa
commit 314647572c
2 changed files with 20 additions and 10 deletions

View File

@ -64,7 +64,7 @@ class LeaveEncashment(Document):
allocation = self.get_leave_allocation() allocation = self.get_leave_allocation()
self.leave_balance = allocation.total_leaves_allocated - get_unused_leaves(self.employee, self.leave_type, self.encashment_date) self.leave_balance = allocation.total_leaves_allocated - get_unused_leaves(self.employee, self.leave_type, allocation.from_date, self.encashment_date)
encashable_days = self.leave_balance - frappe.db.get_value('Leave Type', self.leave_type, 'encashment_threshold_days') encashable_days = self.leave_balance - frappe.db.get_value('Leave Type', self.leave_type, 'encashment_threshold_days')
self.encashable_days = encashable_days if encashable_days > 0 else 0 self.encashable_days = encashable_days if encashable_days > 0 else 0

View File

@ -72,8 +72,11 @@ def get_previous_expiry_ledger_entry(ledger):
''' Returns the expiry ledger entry having same creation date as the ledger entry to be cancelled ''' ''' Returns the expiry ledger entry having same creation date as the ledger entry to be cancelled '''
creation_date = frappe.db.get_value("Leave Ledger Entry", filters={ creation_date = frappe.db.get_value("Leave Ledger Entry", filters={
'transaction_name': ledger.transaction_name, 'transaction_name': ledger.transaction_name,
'is_expired': 0 'is_expired': 0,
}, fieldname=['creation']).strftime(DATE_FORMAT) 'transaction_type': 'Leave Allocation'
}, fieldname=['creation'])
creation_date = creation_date.strftime(DATE_FORMAT) if creation_date else ''
return frappe.db.get_value("Leave Ledger Entry", filters={ return frappe.db.get_value("Leave Ledger Entry", filters={
'creation': ('like', creation_date+"%"), 'creation': ('like', creation_date+"%"),
@ -94,24 +97,31 @@ def process_expired_allocation():
if leave_type_records: if leave_type_records:
leave_type = [record[0] for record in leave_type_records] leave_type = [record[0] for record in leave_type_records]
expired_allocation = frappe.get_all("Leave Ledger Entry",
expired_allocation = frappe.db.sql_list("""SELECT name
FROM `tabLeave Ledger Entry`
WHERE
`transaction_type`='Leave Allocation'
AND `is_expired`=1""")
expire_allocation = frappe.get_all("Leave Ledger Entry",
fields=['leaves', 'to_date', 'employee', 'leave_type', 'is_carry_forward', 'transaction_name as name', 'transaction_type'], fields=['leaves', 'to_date', 'employee', 'leave_type', 'is_carry_forward', 'transaction_name as name', 'transaction_type'],
filters={ filters={
'to_date': add_days(today(), -1), 'to_date': ("<", today()),
'transaction_type': 'Leave Allocation', 'transaction_type': 'Leave Allocation',
'transaction_name': ('not in', expired_allocation)
}, },
or_filters={ or_filters={
'is_carry_forward': 0, 'is_carry_forward': 0,
'leave_type': ('in', leave_type) 'leave_type': ('in', leave_type)
}) })
if expired_allocation: if expire_allocation:
create_expiry_ledger_entry(expired_allocation) create_expiry_ledger_entry(expire_allocation)
def create_expiry_ledger_entry(expired_allocation): def create_expiry_ledger_entry(expire_allocation):
''' Create ledger entry for expired allocation ''' ''' Create ledger entry for expired allocation '''
for allocation in expired_allocation: for allocation in expire_allocation:
if allocation.is_carry_forward: if allocation.is_carry_forward:
expire_carried_forward_allocation(allocation) expire_carried_forward_allocation(allocation)
else: else: