fix(pos): loyalty points in case of returned pos invoice (#30242)
This commit is contained in:
parent
e8310c6dec
commit
7b0a97d679
@ -53,7 +53,7 @@ class POSInvoice(SalesInvoice):
|
|||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
# create the loyalty point ledger entry if the customer is enrolled in any loyalty program
|
# create the loyalty point ledger entry if the customer is enrolled in any loyalty program
|
||||||
if self.loyalty_program:
|
if not self.is_return and self.loyalty_program:
|
||||||
self.make_loyalty_point_entry()
|
self.make_loyalty_point_entry()
|
||||||
elif self.is_return and self.return_against and self.loyalty_program:
|
elif self.is_return and self.return_against and self.loyalty_program:
|
||||||
against_psi_doc = frappe.get_doc("POS Invoice", self.return_against)
|
against_psi_doc = frappe.get_doc("POS Invoice", self.return_against)
|
||||||
@ -87,7 +87,7 @@ class POSInvoice(SalesInvoice):
|
|||||||
def on_cancel(self):
|
def on_cancel(self):
|
||||||
# run on cancel method of selling controller
|
# run on cancel method of selling controller
|
||||||
super(SalesInvoice, self).on_cancel()
|
super(SalesInvoice, self).on_cancel()
|
||||||
if self.loyalty_program:
|
if not self.is_return and self.loyalty_program:
|
||||||
self.delete_loyalty_point_entry()
|
self.delete_loyalty_point_entry()
|
||||||
elif self.is_return and self.return_against and self.loyalty_program:
|
elif self.is_return and self.return_against and self.loyalty_program:
|
||||||
against_psi_doc = frappe.get_doc("POS Invoice", self.return_against)
|
against_psi_doc = frappe.get_doc("POS Invoice", self.return_against)
|
||||||
|
@ -1411,12 +1411,19 @@ class SalesInvoice(SellingController):
|
|||||||
frappe.db.set_value("Customer", self.customer, "loyalty_program_tier", lp_details.tier_name)
|
frappe.db.set_value("Customer", self.customer, "loyalty_program_tier", lp_details.tier_name)
|
||||||
|
|
||||||
def get_returned_amount(self):
|
def get_returned_amount(self):
|
||||||
returned_amount = frappe.db.sql("""
|
from frappe.query_builder.functions import Coalesce, Sum
|
||||||
select sum(grand_total)
|
doc = frappe.qb.DocType(self.doctype)
|
||||||
from `tabSales Invoice`
|
returned_amount = (
|
||||||
where docstatus=1 and is_return=1 and ifnull(return_against, '')=%s
|
frappe.qb.from_(doc)
|
||||||
""", self.name)
|
.select(Sum(doc.grand_total))
|
||||||
return abs(flt(returned_amount[0][0])) if returned_amount else 0
|
.where(
|
||||||
|
(doc.docstatus == 1)
|
||||||
|
& (doc.is_return == 1)
|
||||||
|
& (Coalesce(doc.return_against, '') == self.name)
|
||||||
|
)
|
||||||
|
).run()
|
||||||
|
|
||||||
|
return abs(returned_amount[0][0]) if returned_amount[0][0] else 0
|
||||||
|
|
||||||
# redeem the loyalty points.
|
# redeem the loyalty points.
|
||||||
def apply_loyalty_points(self):
|
def apply_loyalty_points(self):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user