patch: create entries for only missing transactions

This commit is contained in:
Mangesh-Khairnar 2019-05-27 10:58:42 +05:30
parent 45197965d7
commit 24248f687b

View File

@ -7,7 +7,7 @@ import frappe
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 @@ def generate_allocation_ledger_entries(allocation_list):
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 @@ def generate_application_leave_ledger_entries(allocation_list):
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 @@ def generate_encashment_leave_ledger_entries(allocation_list):
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 @@ def get_leaves_application_records(allocation_list):
for allocation in allocation_list:
leave_applications.append(frappe.db.sql("""
SELECT
name,
DISTINCT name,
employee,
leave_type,
total_leave_days,