From 164d7cc896138b1c7bbfbdf00efe39fdb71c9dbb Mon Sep 17 00:00:00 2001 From: ruthra kumar Date: Tue, 22 Oct 2024 16:07:14 +0530 Subject: [PATCH] refactor: handle 'no data' situation in patch (cherry picked from commit 8e3bf7dc09dfdbe51043179dd32c04ab1f61f23e) --- .../create_advance_payment_ledger_records.py | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/erpnext/patches/v15_0/create_advance_payment_ledger_records.py b/erpnext/patches/v15_0/create_advance_payment_ledger_records.py index 64d8e3c0f3c..13b4d95c760 100644 --- a/erpnext/patches/v15_0/create_advance_payment_ledger_records.py +++ b/erpnext/patches/v15_0/create_advance_payment_ledger_records.py @@ -10,6 +10,7 @@ def get_advance_doctypes() -> list: def get_payments_with_so_po_reference() -> list: + advance_payment_entries = [] advance_doctypes = get_advance_doctypes() per = qb.DocType("Payment Entry Reference") payments_with_reference = ( @@ -19,19 +20,21 @@ def get_payments_with_so_po_reference() -> list: .where(per.reference_doctype.isin(advance_doctypes) & per.docstatus.eq(1)) .run() ) - pe = qb.DocType("Payment Entry") - advance_payment_entries = ( - qb.from_(pe) - .select(ConstantColumn("Payment Entry").as_("doctype")) - .select(pe.name) - .where(pe.name.isin(payments_with_reference) & pe.docstatus.eq(1)) - .run(as_dict=True) - ) + if payments_with_reference: + pe = qb.DocType("Payment Entry") + advance_payment_entries = ( + qb.from_(pe) + .select(ConstantColumn("Payment Entry").as_("doctype")) + .select(pe.name) + .where(pe.name.isin(payments_with_reference) & pe.docstatus.eq(1)) + .run(as_dict=True) + ) return advance_payment_entries def get_journals_with_so_po_reference() -> list: + advance_journal_entries = [] advance_doctypes = get_advance_doctypes() jea = qb.DocType("Journal Entry Account") journals_with_reference = ( @@ -41,16 +44,17 @@ def get_journals_with_so_po_reference() -> list: .where(jea.reference_type.isin(advance_doctypes) & jea.docstatus.eq(1)) .run() ) - je = qb.DocType("Journal Entry") - advance_payment_entries = ( - qb.from_(je) - .select(ConstantColumn("Journal Entry").as_("doctype")) - .select(je.name) - .where(je.name.isin(journals_with_reference) & je.docstatus.eq(1)) - .run(as_dict=True) - ) + if journals_with_reference: + je = qb.DocType("Journal Entry") + advance_journal_entries = ( + qb.from_(je) + .select(ConstantColumn("Journal Entry").as_("doctype")) + .select(je.name) + .where(je.name.isin(journals_with_reference) & je.docstatus.eq(1)) + .run(as_dict=True) + ) - return advance_payment_entries + return advance_journal_entries def make_advance_ledger_entries(vouchers: list):