mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-08 15:42:52 +00:00
fix: Remove duplicate leave ledger entry (#21864)
This commit is contained in:
@@ -6,6 +6,7 @@ import frappe
|
|||||||
|
|
||||||
def execute():
|
def execute():
|
||||||
"""Delete duplicate leave ledger entries of type allocation created."""
|
"""Delete duplicate leave ledger entries of type allocation created."""
|
||||||
|
frappe.reload_doc('hr', 'doctype', 'leave_ledger_entry')
|
||||||
if not frappe.db.a_row_exists("Leave Ledger Entry"):
|
if not frappe.db.a_row_exists("Leave Ledger Entry"):
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -15,27 +16,16 @@ def execute():
|
|||||||
def get_duplicate_records():
|
def get_duplicate_records():
|
||||||
"""Fetch all but one duplicate records from the list of expired leave allocation."""
|
"""Fetch all but one duplicate records from the list of expired leave allocation."""
|
||||||
return frappe.db.sql_list("""
|
return frappe.db.sql_list("""
|
||||||
WITH duplicate_records AS
|
SELECT name
|
||||||
(SELECT
|
|
||||||
name, transaction_name, is_carry_forward,
|
|
||||||
ROW_NUMBER() over(partition by transaction_name order by creation)as row
|
|
||||||
FROM `tabLeave Ledger Entry` l
|
|
||||||
WHERE (EXISTS
|
|
||||||
(SELECT name
|
|
||||||
FROM `tabLeave Ledger Entry`
|
FROM `tabLeave Ledger Entry`
|
||||||
WHERE
|
WHERE
|
||||||
transaction_name = l.transaction_name
|
transaction_type = 'Leave Allocation'
|
||||||
AND transaction_type = 'Leave Allocation'
|
|
||||||
AND name <> l.name
|
|
||||||
AND employee = l.employee
|
|
||||||
AND docstatus = 1
|
AND docstatus = 1
|
||||||
AND leave_type = l.leave_type
|
|
||||||
AND is_carry_forward=l.is_carry_forward
|
|
||||||
AND to_date = l.to_date
|
|
||||||
AND from_date = l.from_date
|
|
||||||
AND is_expired = 1
|
AND is_expired = 1
|
||||||
)))
|
GROUP BY
|
||||||
SELECT name FROM duplicate_records WHERE row > 1
|
employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
||||||
|
HAVING
|
||||||
|
count(name) > 1
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def delete_duplicate_ledger_entries(duplicate_records_list):
|
def delete_duplicate_ledger_entries(duplicate_records_list):
|
||||||
|
|||||||
Reference in New Issue
Block a user