mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-31 15:32:27 +00:00
refactor(request_for_quotation): use query builder instead of SQL (#55172)
This commit is contained in:
@@ -378,25 +378,29 @@ class RequestforQuotation(BuyingController):
|
|||||||
return [d.name for d in get_attachments(self.doctype, self.name)]
|
return [d.name for d in get_attachments(self.doctype, self.name)]
|
||||||
|
|
||||||
def update_rfq_supplier_status(self, sup_name=None):
|
def update_rfq_supplier_status(self, sup_name=None):
|
||||||
|
from frappe.query_builder.functions import Count
|
||||||
|
|
||||||
|
SQ = frappe.qb.DocType("Supplier Quotation")
|
||||||
|
SQ_Item = frappe.qb.DocType("Supplier Quotation Item")
|
||||||
|
|
||||||
for supplier in self.suppliers:
|
for supplier in self.suppliers:
|
||||||
if sup_name is None or supplier.supplier == sup_name:
|
if sup_name is None or supplier.supplier == sup_name:
|
||||||
quote_status = _("Received")
|
quote_status = _("Received")
|
||||||
for item in self.items:
|
for item in self.items:
|
||||||
sqi_count = frappe.db.sql(
|
query = (
|
||||||
"""
|
frappe.qb.from_(SQ_Item)
|
||||||
SELECT
|
.join(SQ)
|
||||||
COUNT(sqi.name) as count
|
.on(SQ_Item.parent == SQ.name)
|
||||||
FROM
|
.select(Count(SQ_Item.name).as_("count"))
|
||||||
`tabSupplier Quotation Item` as sqi,
|
.where(SQ.supplier == supplier.supplier)
|
||||||
`tabSupplier Quotation` as sq
|
.where(SQ_Item.docstatus == 1)
|
||||||
WHERE sq.supplier = %(supplier)s
|
.where(SQ_Item.request_for_quotation_item == item.name)
|
||||||
AND sqi.docstatus = 1
|
)
|
||||||
AND sqi.request_for_quotation_item = %(rqi)s
|
|
||||||
AND sqi.parent = sq.name""",
|
result = query.run(as_dict=True)
|
||||||
{"supplier": supplier.supplier, "rqi": item.name},
|
sqi_count = result[0] if result else frappe._dict(count=0)
|
||||||
as_dict=1,
|
|
||||||
)[0]
|
if sqi_count.count == 0:
|
||||||
if (sqi_count.count) == 0:
|
|
||||||
quote_status = _("Pending")
|
quote_status = _("Pending")
|
||||||
supplier.quote_status = quote_status
|
supplier.quote_status = quote_status
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user