mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 05:09: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
|
# valdite the redemption and then delete the loyalty points earned on cancel of the invoice
|
||||||
def delete_loyalty_point_entry(self):
|
def delete_loyalty_point_entry(self):
|
||||||
lp_entry = frappe.db.sql(
|
lp_entry = frappe.db.get_all(
|
||||||
"select name from `tabLoyalty Point Entry` where invoice=%s", (self.name), as_dict=1
|
"Loyalty Point Entry", filters={"invoice": self.name, "loyalty_points": (">", 0)}, fields=["name"]
|
||||||
)
|
)
|
||||||
|
|
||||||
if not lp_entry:
|
if not lp_entry:
|
||||||
return
|
return
|
||||||
against_lp_entry = frappe.db.sql(
|
|
||||||
"""select name, invoice from `tabLoyalty Point Entry`
|
against_lp_entry = frappe.db.get_all(
|
||||||
where redeem_against=%s""",
|
"Loyalty Point Entry",
|
||||||
(lp_entry[0].name),
|
filters={"redeem_against": lp_entry[0].name},
|
||||||
as_dict=1,
|
fields=["name", "invoice"],
|
||||||
)
|
)
|
||||||
|
|
||||||
if against_lp_entry:
|
if against_lp_entry:
|
||||||
invoice_list = ", ".join([d.invoice for d in against_lp_entry])
|
invoice_list = ", ".join([d.invoice for d in against_lp_entry])
|
||||||
frappe.throw(
|
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)
|
).format(self.doctype, self.doctype, invoice_list)
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
frappe.db.sql("""delete from `tabLoyalty Point Entry` where invoice=%s""", (self.name))
|
frappe.db.delete("Loyalty Point Entry", filters={"invoice": self.name})
|
||||||
# Set loyalty program
|
|
||||||
self.set_loyalty_program_tier()
|
self.set_loyalty_program_tier()
|
||||||
|
|
||||||
def set_loyalty_program_tier(self):
|
def set_loyalty_program_tier(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user