Skip to content

Commit

Permalink
fix: Remove duplicate leave ledger entry (#21867)
Browse files Browse the repository at this point in the history
  • Loading branch information
nabinhait committed May 22, 2020
1 parent 5f82999 commit 1287f16
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions erpnext/patches/v12_0/remove_duplicate_leave_ledger_entries.py
Expand Up @@ -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'
Expand All @@ -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))

0 comments on commit 1287f16

Please sign in to comment.