From 3a6b095ed45fbc47628e4b189e1d1a89e17ffc25 Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 23 Aug 2022 15:10:55 +0530 Subject: [PATCH] chore: patch for migrating remarks to payment ledger --- ...grate_remarks_from_gl_to_payment_ledger.py | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py diff --git a/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py b/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py new file mode 100644 index 0000000000..062d24b78b --- /dev/null +++ b/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py @@ -0,0 +1,56 @@ +import frappe +from frappe import qb +from frappe.utils import create_batch + + +def execute(): + if frappe.reload_doc("accounts", "doctype", "payment_ledger_entry"): + + gle = qb.DocType("GL Entry") + ple = qb.DocType("Payment Ledger Entry") + + # get ple and their remarks from GL Entry + pl_entries = ( + qb.from_(ple) + .left_join(gle) + .on( + (ple.account == gle.account) + & (ple.party_type == gle.party_type) + & (ple.party == gle.party) + & (ple.voucher_type == gle.voucher_type) + & (ple.voucher_no == gle.voucher_no) + & (ple.company == gle.company) + ) + .select( + ple.company, + ple.account, + ple.party_type, + ple.party, + ple.voucher_type, + ple.voucher_no, + gle.remarks.as_("gle_remarks"), + ) + .where((ple.delinked == 0) & (gle.is_cancelled == 0)) + .run(as_dict=True) + ) + + if pl_entries: + # split into multiple batches, update and commit for each batch + batch_size = 1000 + for batch in create_batch(pl_entries, batch_size): + for entry in batch: + query = ( + qb.update(ple) + .set(ple.remarks, entry.gle_remarks) + .where( + (ple.company == entry.company) + & (ple.account == entry.account) + & (ple.party_type == entry.party_type) + & (ple.party == entry.party) + & (ple.voucher_type == entry.voucher_type) + & (ple.voucher_no == entry.voucher_no) + ) + ) + query.run() + + frappe.db.commit()