mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-14 02:31:21 +00:00
refactor(supplier): Using query builder for get_total_accepted_amount (#54873)
Use the query builder for get_total_accepted_amount to assure compatibility with PostgreSQL.
This commit is contained in:
@@ -327,28 +327,21 @@ def get_total_rejected_items(scorecard):
|
|||||||
|
|
||||||
def get_total_accepted_amount(scorecard):
|
def get_total_accepted_amount(scorecard):
|
||||||
"""Gets the total amount (in company currency) accepted in the period (based on Purchase Receipts)"""
|
"""Gets the total amount (in company currency) accepted in the period (based on Purchase Receipts)"""
|
||||||
supplier = frappe.get_doc("Supplier", scorecard.supplier)
|
pr = frappe.qb.DocType("Purchase Receipt")
|
||||||
|
pr_item = frappe.qb.DocType("Purchase Receipt Item")
|
||||||
|
|
||||||
# Look up all PO Items with delivery dates between our dates
|
query = (
|
||||||
data = frappe.db.sql(
|
frappe.qb.from_(pr)
|
||||||
"""
|
.join(pr_item)
|
||||||
SELECT
|
.on(pr_item.parent == pr.name)
|
||||||
SUM(pr_item.qty * pr_item.base_rate)
|
.select(frappe.qb.fn.Sum(pr_item.qty * pr_item.base_rate))
|
||||||
FROM
|
.where(pr.supplier == scorecard.supplier)
|
||||||
`tabPurchase Receipt Item` pr_item,
|
.where(pr.posting_date[scorecard.start_date : scorecard.end_date])
|
||||||
`tabPurchase Receipt` pr
|
.where(pr_item.docstatus == 1)
|
||||||
WHERE
|
)
|
||||||
pr.supplier = %(supplier)s
|
|
||||||
AND pr.posting_date BETWEEN %(start_date)s AND %(end_date)s
|
|
||||||
AND pr_item.docstatus = 1
|
|
||||||
AND pr_item.parent = pr.name""",
|
|
||||||
{"supplier": supplier.name, "start_date": scorecard.start_date, "end_date": scorecard.end_date},
|
|
||||||
as_dict=0,
|
|
||||||
)[0][0]
|
|
||||||
|
|
||||||
if not data:
|
result = query.run()
|
||||||
data = 0
|
return frappe.utils.flt(result[0][0]) if result else 0.0
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def get_total_accepted_items(scorecard):
|
def get_total_accepted_items(scorecard):
|
||||||
|
|||||||
Reference in New Issue
Block a user