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