From 42383c3f36fb7891eb6d57139ba7dcb075a632bd Mon Sep 17 00:00:00 2001 From: Loic Oberle Date: Wed, 3 Jun 2026 07:59:04 +0200 Subject: [PATCH] =?UTF-8?q?refactor(sales=5Finvoice):=20replace=20sql=20wi?= =?UTF-8?q?th=20qb=20in=20delete=5Floyalty=5Fpoint=5F=E2=80=A6=20(#55379)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../doctype/sales_invoice/sales_invoice.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index 52cda6572e5..bd264884509 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -2218,28 +2218,29 @@ class SalesInvoice(SellingController): # valdite the redemption and then delete the loyalty points earned on cancel of the invoice def delete_loyalty_point_entry(self): - lp_entry = frappe.db.sql( - "select name from `tabLoyalty Point Entry` where invoice=%s", (self.name), as_dict=1 + lp_entry = frappe.db.get_all( + "Loyalty Point Entry", filters={"invoice": self.name, "loyalty_points": (">", 0)}, fields=["name"] ) if not lp_entry: return - against_lp_entry = frappe.db.sql( - """select name, invoice from `tabLoyalty Point Entry` - where redeem_against=%s""", - (lp_entry[0].name), - as_dict=1, + + against_lp_entry = frappe.db.get_all( + "Loyalty Point Entry", + filters={"redeem_against": lp_entry[0].name}, + fields=["name", "invoice"], ) + if against_lp_entry: invoice_list = ", ".join([d.invoice for d in against_lp_entry]) frappe.throw( _( - """{} can't be cancelled since the Loyalty Points earned has been redeemed. First cancel the {} No {}""" + "{} can't be cancelled since the Loyalty Points earned has been redeemed. " + "First cancel the {} No {}" ).format(self.doctype, self.doctype, invoice_list) ) else: - frappe.db.sql("""delete from `tabLoyalty Point Entry` where invoice=%s""", (self.name)) - # Set loyalty program + frappe.db.delete("Loyalty Point Entry", filters={"invoice": self.name}) self.set_loyalty_program_tier() def set_loyalty_program_tier(self):