mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 18:21:22 +00:00
refactor(supplier): Using query builder for get_sq_total_items (#54879)
Use the query builder for get_sq_total_items to assure compatibility with PostgreSQL.
This commit is contained in:
@@ -562,35 +562,32 @@ def get_sq_total_number(scorecard):
|
||||
|
||||
def get_sq_total_items(scorecard):
|
||||
"""Gets the total number of RFQ items 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")
|
||||
sq = frappe.qb.DocType("Supplier Quotation")
|
||||
sq_item = frappe.qb.DocType("Supplier Quotation Item")
|
||||
|
||||
# Look up all PO Items with delivery dates between our dates
|
||||
data = frappe.db.sql(
|
||||
"""
|
||||
SELECT
|
||||
COUNT(sq_item.name) as total_sqs
|
||||
FROM
|
||||
`tabRequest for Quotation Item` rfq_item,
|
||||
`tabSupplier Quotation Item` sq_item,
|
||||
`tabSupplier Quotation` sq,
|
||||
`tabRequest for Quotation Supplier` rfq_sup,
|
||||
`tabRequest for Quotation` rfq
|
||||
WHERE
|
||||
rfq_sup.supplier = %(supplier)s
|
||||
AND rfq.transaction_date BETWEEN %(start_date)s AND %(end_date)s
|
||||
AND sq_item.request_for_quotation_item = rfq_item.name
|
||||
AND sq_item.docstatus = 1
|
||||
AND sq.supplier = %(supplier)s
|
||||
AND sq_item.parent = sq.name
|
||||
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:
|
||||
data = 0
|
||||
return data
|
||||
query = (
|
||||
frappe.qb.from_(rfq)
|
||||
.join(rfq_item)
|
||||
.on(rfq_item.parent == rfq.name)
|
||||
.join(rfq_sup)
|
||||
.on(rfq_sup.parent == rfq.name)
|
||||
.join(sq_item)
|
||||
.on(sq_item.request_for_quotation_item == rfq_item.name)
|
||||
.join(sq)
|
||||
.on(sq_item.parent == sq.name)
|
||||
.select(frappe.qb.fn.Count(sq_item.name))
|
||||
.where(rfq_sup.supplier == scorecard.supplier)
|
||||
.where(sq.supplier == scorecard.supplier)
|
||||
.where(rfq.transaction_date[scorecard.start_date : scorecard.end_date])
|
||||
.where(rfq_item.docstatus == 1)
|
||||
.where(sq_item.docstatus == 1)
|
||||
)
|
||||
|
||||
result = query.run()
|
||||
return frappe.utils.cint(result[0][0]) if result else 0
|
||||
|
||||
|
||||
def get_rfq_response_days(scorecard):
|
||||
|
||||
Reference in New Issue
Block a user