refactor(supplier_qotation): Replace sql by query builder (#55154)

This commit is contained in:
Loic Oberle
2026-05-22 12:39:15 +02:00
committed by GitHub
parent ab99c9a54e
commit f6bf7d85ad

View File

@@ -170,6 +170,8 @@ class SupplierQuotation(BuyingController):
frappe.throw(_("Valid till Date cannot be before Transaction Date")) frappe.throw(_("Valid till Date cannot be before Transaction Date"))
def update_rfq_supplier_status(self, include_me): def update_rfq_supplier_status(self, include_me):
from frappe.query_builder.functions import Count
rfq_list = set([]) rfq_list = set([])
for item in self.items: for item in self.items:
if item.request_for_quotation: if item.request_for_quotation:
@@ -194,22 +196,25 @@ class SupplierQuotation(BuyingController):
) )
quote_status = _("Received") quote_status = _("Received")
SQ = frappe.qb.DocType("Supplier Quotation")
SQ_Item = frappe.qb.DocType("Supplier Quotation Item")
for item in doc.items: for item in doc.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 == self.supplier)
`tabSupplier Quotation` as sq .where(SQ_Item.docstatus == 1)
WHERE sq.supplier = %(supplier)s .where(SQ.name != self.name)
AND sqi.docstatus = 1 .where(SQ_Item.request_for_quotation_item == item.name)
AND sq.name != %(me)s )
AND sqi.request_for_quotation_item = %(rqi)s
AND sqi.parent = sq.name""", result = query.run(as_dict=True)
{"supplier": self.supplier, "rqi": item.name, "me": self.name}, sqi_count = result[0] if result else frappe._dict(count=0)
as_dict=1,
)[0]
self_count = ( self_count = (
sum(my_item.request_for_quotation_item == item.name for my_item in self.items) sum(my_item.request_for_quotation_item == item.name for my_item in self.items)
if include_me if include_me