patch: create entries for only missing transactions
diff --git a/erpnext/patches/v12_0/generate_leave_ledger_entries.py b/erpnext/patches/v12_0/generate_leave_ledger_entries.py
index 9223bb2..9c638ab 100644
--- a/erpnext/patches/v12_0/generate_leave_ledger_entries.py
+++ b/erpnext/patches/v12_0/generate_leave_ledger_entries.py
@@ -7,7 +7,7 @@
def execute():
""" Generates leave ledger entries for leave allocation/application/encashment
for last allocation """
- if frappe.db.exists("DocType","Leave Ledger Entry"):
+ if frappe.db.a_row_exists("Leave Ledger Entry"):
return
allocation_list = get_allocation_records()
@@ -20,7 +20,9 @@
from erpnext.hr.doctype.leave_allocation.leave_allocation import LeaveAllocation
for allocation in allocation_list:
- LeaveAllocation.create_leave_ledger_entry(allocation)
+ if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Allocation',
+ 'transaction_name': allocation.name}):
+ LeaveAllocation.create_leave_ledger_entry(allocation)
def generate_application_leave_ledger_entries(allocation_list):
''' fix ledger entries for missing leave application transaction '''
@@ -29,7 +31,9 @@
leave_applications = get_leaves_application_records(allocation_list)
for record in leave_applications:
- LeaveApplication.create_leave_ledger_entry(record)
+ if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Application',
+ 'transaction_name': record.name}):
+ LeaveApplication.create_leave_ledger_entry(record)
def generate_encashment_leave_ledger_entries(allocation_list):
''' fix ledger entries for missing leave encashment transaction '''
@@ -38,7 +42,9 @@
leave_encashments = get_leave_encashment_records(allocation_list)
for record in leave_encashments:
- LeaveEncashment.create_leave_ledger_entry(record)
+ if not frappe.db.exists("Leave Ledger Entry", {'transaction_type': 'Leave Encashment',
+ 'transaction_name': record.name}):
+ LeaveEncashment.create_leave_ledger_entry(record)
def get_allocation_records():
return frappe.db.sql("""
@@ -62,7 +68,7 @@
for allocation in allocation_list:
leave_applications.append(frappe.db.sql("""
SELECT
- name,
+ DISTINCT name,
employee,
leave_type,
total_leave_days,