refactor: remove duplicate entries on remarks migration patch

This commit is contained in:
ruthra kumar 2022-10-04 12:35:59 +05:30
parent 8b21d27f04
commit 518ab93e03

View File

@ -3,6 +3,29 @@ from frappe import qb
from frappe.utils import create_batch
def remove_duplicate_entries(pl_entries):
unique_vouchers = set()
for x in pl_entries:
unique_vouchers.add(
(x.company, x.account, x.party_type, x.party, x.voucher_type, x.voucher_no, x.gle_remarks)
)
entries = []
for x in unique_vouchers:
entries.append(
frappe._dict(
company=x[0],
account=x[1],
party_type=x[2],
party=x[3],
voucher_type=x[4],
voucher_no=x[5],
gle_remarks=x[6],
)
)
return entries
def execute():
if frappe.reload_doc("accounts", "doctype", "payment_ledger_entry"):
@ -34,6 +57,8 @@ def execute():
.run(as_dict=True)
)
pl_entries = remove_duplicate_entries(pl_entries)
if pl_entries:
# split into multiple batches, update and commit for each batch
batch_size = 1000