fix: expiry logic for carry forwarded allocation
This commit is contained in:
parent
9bb4b8e8b2
commit
170b8dded8
@ -12,6 +12,7 @@
|
||||
"from_date",
|
||||
"to_date",
|
||||
"is_carry_forward",
|
||||
"is_expired",
|
||||
"amended_from"
|
||||
],
|
||||
"fields": [
|
||||
@ -72,10 +73,15 @@
|
||||
"fieldname": "is_carry_forward",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Carry Forward"
|
||||
},
|
||||
{
|
||||
"fieldname": "is_expired",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Expired"
|
||||
}
|
||||
],
|
||||
"is_submittable": 1,
|
||||
"modified": "2019-05-09 18:36:07.383714",
|
||||
"modified": "2019-05-13 12:56:45.542495",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "Leave Ledger Entry",
|
||||
|
@ -9,7 +9,10 @@ from frappe import _
|
||||
from frappe.utils import add_days, today
|
||||
|
||||
class LeaveLedgerEntry(Document):
|
||||
pass
|
||||
def validate_entries(self):
|
||||
leave_records = frappe.get_all('Leave Ledger Entry', ['leaves'])
|
||||
if sum(record.get("leaves") for record in leave_records) <0:
|
||||
frappe.throw(_("Invalid Ledger Entry"))
|
||||
|
||||
def create_leave_ledger_entry(ref_doc, args, submit=True):
|
||||
ledger = frappe._dict(
|
||||
@ -19,7 +22,7 @@ def create_leave_ledger_entry(ref_doc, args, submit=True):
|
||||
leave_type=ref_doc.leave_type,
|
||||
from_date=ref_doc.from_date,
|
||||
transaction_type=ref_doc.doctype,
|
||||
transaction_name=ref_doc.name
|
||||
transaction_name=ref_doc.name,
|
||||
)
|
||||
ledger.update(args)
|
||||
|
||||
@ -52,22 +55,42 @@ def delete_ledger_entry(ledger):
|
||||
def check_expired_allocation():
|
||||
''' Checks for expired allocation by comparing to_date with current_date and
|
||||
based on that creates an expiry ledger entry '''
|
||||
expired_allocation = frappe.db.get_all("Leave Ledger Allocation",
|
||||
expired_allocation = frappe.get_all("Leave Ledger Allocation",
|
||||
filters={
|
||||
'to_date': today(),
|
||||
'transaction_type': 'Leave Allocation'
|
||||
},
|
||||
fields=['name', 'transaction_name'])
|
||||
fields=['*'])
|
||||
|
||||
if expired_allocation:
|
||||
create_expiry_ledger_entry(expired_allocation)
|
||||
|
||||
def create_expiry_ledger_entry(expired_allocation):
|
||||
for allocation in expired_allocation:
|
||||
ledger_entry = frappe.get_doc('Leave Ledger Entry', allocation.name)
|
||||
args = {
|
||||
'leaves': -ledger_entry.leaves,
|
||||
'to_date': '',
|
||||
'is_carry_forward': ledger_entry.is_carry_forward
|
||||
}
|
||||
create_leave_ledger_entry(ledger_entry, args)
|
||||
filters = {
|
||||
'employee': allocation.employee,
|
||||
'leave_type': allocation.leave_type,
|
||||
'from_date': ('>=', allocation.from_date),
|
||||
}
|
||||
# get only application ledger entries in case of carry forward
|
||||
if allocation.is_carry_forward:
|
||||
filters.update(dict(transaction_type='Leave Application'))
|
||||
|
||||
leave_records = frappe.get_all("Leave Ledger Entry",
|
||||
filters=filters,
|
||||
fields=['leaves'])
|
||||
|
||||
leaves = sum(record.get("leaves") for record in leave_records)
|
||||
|
||||
if allocation.is_carry_forward:
|
||||
leaves = allocation.leaves + leaves
|
||||
|
||||
if leaves > 0:
|
||||
args = frappe._dict(
|
||||
leaves=allocation.leaves * -1,
|
||||
to_date='',
|
||||
is_carry_forward=allocation.is_carry_forward,
|
||||
is_expired=1,
|
||||
from_date=allocation.to_date
|
||||
)
|
||||
create_leave_ledger_entry(allocation, args)
|
Loading…
x
Reference in New Issue
Block a user