From 618045ec98505b122565d6afe03ec7ba70dfcd2e Mon Sep 17 00:00:00 2001 From: Loic Oberle Date: Fri, 29 May 2026 14:04:20 +0200 Subject: [PATCH] refactor(sales_invoice): replace sql with qb in get_all_mode_of_payments (#55377) --- .../doctype/sales_invoice/sales_invoice.py | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 781f1d0cada..db1e56a2b7c 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -3142,15 +3142,22 @@ def update_multi_mode_option(doc, pos_profile): def get_all_mode_of_payments(doc): - return frappe.db.sql( - """ - select mpa.default_account, mpa.parent, mp.type as type - from `tabMode of Payment Account` mpa,`tabMode of Payment` mp - where mpa.parent = mp.name and mpa.company = %(company)s and mp.enabled = 1""", - {"company": doc.company}, - as_dict=1, + ModeOfPaymentAccount = frappe.qb.DocType("Mode of Payment Account") + ModeOfPayment = frappe.qb.DocType("Mode of Payment") + + query = ( + frappe.qb.from_(ModeOfPaymentAccount) + .join(ModeOfPayment) + .on(ModeOfPaymentAccount.parent == ModeOfPayment.name) + .select( + ModeOfPaymentAccount.default_account, ModeOfPaymentAccount.parent, ModeOfPayment.type.as_("type") + ) + .where(ModeOfPaymentAccount.company == doc.company) + .where(ModeOfPayment.enabled == 1) ) + return query.run(as_dict=1) + def get_mode_of_payments_info(mode_of_payments, company): data = frappe.db.sql(