mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 10:11:20 +00:00
fix: expiry allocaton after creating all the transactions
This commit is contained in:
@@ -6,88 +6,96 @@ import frappe
|
|||||||
from frappe.utils import getdate
|
from frappe.utils import getdate
|
||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
""" Generates leave ledger entries for leave allocation/application/encashment
|
""" Generates leave ledger entries for leave allocation/application/encashment
|
||||||
for last allocation """
|
for last allocation """
|
||||||
frappe.reload_doc("HR", "doctype", "Leave Ledger Entry")
|
frappe.reload_doc("HR", "doctype", "Leave Ledger Entry")
|
||||||
frappe.reload_doc("HR", "doctype", "Leave Encashment")
|
frappe.reload_doc("HR", "doctype", "Leave Encashment")
|
||||||
if frappe.db.a_row_exists("Leave Ledger Entry"):
|
if frappe.db.a_row_exists("Leave Ledger Entry"):
|
||||||
return
|
return
|
||||||
|
|
||||||
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 '''
|
||||||
allocation_list = get_allocation_records()
|
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}):
|
|
||||||
allocation.update(dict(doctype="Leave Allocation"))
|
|
||||||
allocation_obj = frappe.get_doc(allocation)
|
|
||||||
allocation_obj.create_leave_ledger_entry()
|
|
||||||
if allocation.to_date <= getdate():
|
|
||||||
allocation_obj.expire_allocation()
|
|
||||||
|
|
||||||
|
for allocation in allocation_list:
|
||||||
|
if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Allocation', 'transaction_name': allocation.name}):
|
||||||
|
allocation.update(dict(doctype="Leave Allocation"))
|
||||||
|
allocation_obj = frappe.get_doc(allocation)
|
||||||
|
allocation_obj.create_leave_ledger_entry()
|
||||||
|
|
||||||
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 '''
|
||||||
leave_applications = get_leaves_application_records()
|
leave_applications = get_leaves_application_records()
|
||||||
|
|
||||||
for application in leave_applications:
|
for application in leave_applications:
|
||||||
if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Application', 'transaction_name': application.name}):
|
if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Application', 'transaction_name': application.name}):
|
||||||
application.update(dict(doctype="Leave Application"))
|
application.update(dict(doctype="Leave Application"))
|
||||||
frappe.get_doc(application).create_leave_ledger_entry()
|
frappe.get_doc(application).create_leave_ledger_entry()
|
||||||
|
|
||||||
def generate_encashment_leave_ledger_entries():
|
def generate_encashment_leave_ledger_entries():
|
||||||
''' fix ledger entries for missing leave encashment transaction '''
|
''' fix ledger entries for missing leave encashment transaction '''
|
||||||
leave_encashments = get_leave_encashment_records()
|
leave_encashments = get_leave_encashment_records()
|
||||||
|
|
||||||
for encashment in leave_encashments:
|
for encashment in leave_encashments:
|
||||||
if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Encashment', 'transaction_name': encashment.name}):
|
if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Encashment', 'transaction_name': encashment.name}):
|
||||||
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,
|
||||||
carry_forwarded_leaves,
|
carry_forwarded_leaves,
|
||||||
from_date,
|
from_date,
|
||||||
to_date,
|
to_date,
|
||||||
carry_forward
|
carry_forward
|
||||||
FROM `tabLeave Allocation`
|
FROM `tabLeave Allocation`
|
||||||
WHERE
|
WHERE
|
||||||
docstatus=1
|
docstatus=1
|
||||||
ORDER BY to_date ASC
|
ORDER BY to_date ASC
|
||||||
""", as_dict=1)
|
""", as_dict=1)
|
||||||
|
|
||||||
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,
|
||||||
from_date,
|
from_date,
|
||||||
to_date
|
to_date
|
||||||
FROM `tabLeave Application`
|
FROM `tabLeave Application`
|
||||||
WHERE
|
WHERE
|
||||||
docstatus=1
|
docstatus=1
|
||||||
""", as_dict=1)
|
""", as_dict=1)
|
||||||
|
|
||||||
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,
|
||||||
encashment_date
|
encashment_date
|
||||||
FROM `tabLeave Encashment`
|
FROM `tabLeave Encashment`
|
||||||
WHERE
|
WHERE
|
||||||
docstatus=1
|
docstatus=1
|
||||||
""", as_dict=1)
|
""", as_dict=1)
|
||||||
Reference in New Issue
Block a user