perf(invoice): Faster return amount query (#36556)
perf: Faster return amount query
This commit is contained in:
parent
e64b004eca
commit
b0c79a0467
@ -1654,15 +1654,13 @@ 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):
|
||||||
from frappe.query_builder.functions import Coalesce, Sum
|
from frappe.query_builder.functions import Sum
|
||||||
|
|
||||||
doc = frappe.qb.DocType(self.doctype)
|
doc = frappe.qb.DocType(self.doctype)
|
||||||
returned_amount = (
|
returned_amount = (
|
||||||
frappe.qb.from_(doc)
|
frappe.qb.from_(doc)
|
||||||
.select(Sum(doc.grand_total))
|
.select(Sum(doc.grand_total))
|
||||||
.where(
|
.where((doc.docstatus == 1) & (doc.is_return == 1) & (doc.return_against == self.name))
|
||||||
(doc.docstatus == 1) & (doc.is_return == 1) & (Coalesce(doc.return_against, "") == self.name)
|
|
||||||
)
|
|
||||||
).run()
|
).run()
|
||||||
|
|
||||||
return abs(returned_amount[0][0]) if returned_amount[0][0] else 0
|
return abs(returned_amount[0][0]) if returned_amount[0][0] else 0
|
||||||
|
Loading…
Reference in New Issue
Block a user