mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-18 09:05:00 +00:00
fix: Remove duplicate leave ledger entry (#21867)
This commit is contained in:
@@ -15,8 +15,8 @@ def execute():
|
||||
|
||||
def get_duplicate_records():
|
||||
"""Fetch all but one duplicate records from the list of expired leave allocation."""
|
||||
return frappe.db.sql_list("""
|
||||
SELECT name
|
||||
return frappe.db.sql("""
|
||||
SELECT name, employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
||||
FROM `tabLeave Ledger Entry`
|
||||
WHERE
|
||||
transaction_type = 'Leave Allocation'
|
||||
@@ -26,9 +26,21 @@ def get_duplicate_records():
|
||||
employee, transaction_name, leave_type, is_carry_forward, from_date, to_date
|
||||
HAVING
|
||||
count(name) > 1
|
||||
ORDER BY
|
||||
creation
|
||||
""")
|
||||
|
||||
def delete_duplicate_ledger_entries(duplicate_records_list):
|
||||
"""Delete duplicate leave ledger entries."""
|
||||
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