fix: expiry allocaton after creating all the transactions

This commit is contained in:
Mangesh-Khairnar
2019-07-22 17:47:03 +05:30
parent f6cf58fa8c
commit 08c02287dd

View File

@@ -16,6 +16,7 @@ def execute():
generate_allocation_ledger_entries() generate_allocation_ledger_entries()
generate_application_leave_ledger_entries() generate_application_leave_ledger_entries()
generate_encashment_leave_ledger_entries() generate_encashment_leave_ledger_entries()
generate_expiry_allocation_ledger_entries()
def generate_allocation_ledger_entries(): def generate_allocation_ledger_entries():
''' fix ledger entries for missing leave allocation transaction ''' ''' fix ledger entries for missing leave allocation transaction '''
@@ -26,9 +27,6 @@ def generate_allocation_ledger_entries():
allocation.update(dict(doctype="Leave Allocation")) allocation.update(dict(doctype="Leave Allocation"))
allocation_obj = frappe.get_doc(allocation) allocation_obj = frappe.get_doc(allocation)
allocation_obj.create_leave_ledger_entry() allocation_obj.create_leave_ledger_entry()
if allocation.to_date <= getdate():
allocation_obj.expire_allocation()
def generate_application_leave_ledger_entries(): def generate_application_leave_ledger_entries():
''' fix ledger entries for missing leave application transaction ''' ''' fix ledger entries for missing leave application transaction '''
@@ -48,10 +46,20 @@ def generate_encashment_leave_ledger_entries():
encashment.update(dict(doctype="Leave Encashment")) encashment.update(dict(doctype="Leave Encashment"))
frappe.get_doc(encashment).create_leave_ledger_entry() frappe.get_doc(encashment).create_leave_ledger_entry()
def generate_expiry_allocation_ledger_entries():
''' fix ledger entries for missing leave allocation transaction '''
allocation_list = get_allocation_records()
for allocation in allocation_list:
if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Allocation', 'transaction_name': allocation.name, 'is_expired': 1}):
allocation.update(dict(doctype="Leave Allocation"))
allocation_obj = frappe.get_doc(allocation)
allocation_obj.expire_allocation()
def get_allocation_records(): def get_allocation_records():
return frappe.db.sql(""" return frappe.db.sql("""
SELECT SELECT
DISTINCT name, name,
employee, employee,
leave_type, leave_type,
new_leaves_allocated, new_leaves_allocated,
@@ -68,7 +76,7 @@ def get_allocation_records():
def get_leaves_application_records(): def get_leaves_application_records():
return frappe.db.sql(""" return frappe.db.sql("""
SELECT SELECT
DISTINCT name, name,
employee, employee,
leave_type, leave_type,
total_leave_days, total_leave_days,
@@ -82,7 +90,7 @@ def get_leaves_application_records():
def get_leave_encashment_records(): def get_leave_encashment_records():
return frappe.db.sql(""" return frappe.db.sql("""
SELECT SELECT
DISTINCT name, name,
employee, employee,
leave_type, leave_type,
encashable_days, encashable_days,