mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-14 10:41:21 +00:00
refactor(supplier): Using query builder for get_rfq_total_number (#54876)
Use the query builder for get_rfq_total_number to assure compatibility with PostgreSQL.
This commit is contained in:
@@ -474,30 +474,24 @@ def get_invoiced_qty(scorecard):
|
|||||||
|
|
||||||
def get_rfq_total_number(scorecard):
|
def get_rfq_total_number(scorecard):
|
||||||
"""Gets the total number of RFQs sent to supplier"""
|
"""Gets the total number of RFQs sent to supplier"""
|
||||||
supplier = frappe.get_doc("Supplier", scorecard.supplier)
|
rfq = frappe.qb.DocType("Request for Quotation")
|
||||||
|
rfq_item = frappe.qb.DocType("Request for Quotation Item")
|
||||||
|
rfq_sup = frappe.qb.DocType("Request for Quotation Supplier")
|
||||||
|
|
||||||
# Look up all PO Items with delivery dates between our dates
|
query = (
|
||||||
data = frappe.db.sql(
|
frappe.qb.from_(rfq)
|
||||||
"""
|
.join(rfq_item)
|
||||||
SELECT
|
.on(rfq_item.parent == rfq.name)
|
||||||
COUNT(rfq.name) as total_rfqs
|
.join(rfq_sup)
|
||||||
FROM
|
.on(rfq_sup.parent == rfq.name)
|
||||||
`tabRequest for Quotation Item` rfq_item,
|
.select(frappe.qb.fn.Count(rfq.name))
|
||||||
`tabRequest for Quotation Supplier` rfq_sup,
|
.where(rfq_sup.supplier == scorecard.supplier)
|
||||||
`tabRequest for Quotation` rfq
|
.where(rfq.transaction_date[scorecard.start_date : scorecard.end_date])
|
||||||
WHERE
|
.where(rfq_item.docstatus == 1)
|
||||||
rfq_sup.supplier = %(supplier)s
|
)
|
||||||
AND rfq.transaction_date BETWEEN %(start_date)s AND %(end_date)s
|
|
||||||
AND rfq_item.docstatus = 1
|
|
||||||
AND rfq_item.parent = rfq.name
|
|
||||||
AND rfq_sup.parent = rfq.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.cint(result[0][0]) if result else 0
|
||||||
return data
|
|
||||||
|
|
||||||
|
|
||||||
def get_rfq_total_items(scorecard):
|
def get_rfq_total_items(scorecard):
|
||||||
|
|||||||
Reference in New Issue
Block a user