mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-16 11:39:18 +00:00
fix: Remove duplicate leave ledger entry (#21867)
This commit is contained in:
@@ -15,8 +15,8 @@ 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("""
|
||||||
SELECT name
|
SELECT name, employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
||||||
FROM `tabLeave Ledger Entry`
|
FROM `tabLeave Ledger Entry`
|
||||||
WHERE
|
WHERE
|
||||||
transaction_type = 'Leave Allocation'
|
transaction_type = 'Leave Allocation'
|
||||||
@@ -26,9 +26,21 @@ def get_duplicate_records():
|
|||||||
employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
||||||
HAVING
|
HAVING
|
||||||
count(name) > 1
|
count(name) > 1
|
||||||
|
ORDER BY
|
||||||
|
creation
|
||||||
""")
|
""")
|
||||||
|
|
||||||
def delete_duplicate_ledger_entries(duplicate_records_list):
|
def delete_duplicate_ledger_entries(duplicate_records_list):
|
||||||
"""Delete duplicate leave ledger entries."""
|
"""Delete duplicate leave ledger entries."""
|
||||||
if not duplicate_records_list: return
|
if not duplicate_records_list: return
|
||||||
frappe.db.sql('''DELETE FROM `tabLeave Ledger Entry` WHERE name in %s''', ((tuple(duplicate_records_list)), ))
|
for d in duplicate_records_list:
|
||||||
|
frappe.db.sql('''
|
||||||
|
DELETE FROM `tabLeave Ledger Entry`
|
||||||
|
WHERE name != %s
|
||||||
|
AND employee = %s
|
||||||
|
AND transaction_name = %s
|
||||||
|
AND leave_type = %s
|
||||||
|
AND is_carry_forward = %s
|
||||||
|
AND from_date = %s
|
||||||
|
AND to_date = %s
|
||||||
|
''', tuple(d))
|
||||||
Reference in New Issue
Block a user