refactor(sales_invoice): replace sql with qb in delete_loyalty_point_… (#55379)

This commit is contained in:
Loic Oberle
2026-06-03 07:59:04 +02:00
committed by GitHub
parent 3b2f2168d0
commit 42383c3f36

View File

@@ -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):