mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-04 20:59:11 +00:00
refactor(sales_invoice): replace sql with qb in delete_loyalty_point_… (#55379)
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user