mirror of
https://github.com/frappe/erpnext.git
synced 2026-06-05 13:24:47 +00:00
refactor(purchase-order): use ORM syntax for min order quantity query (#54778)
* refactor(purchase-order): use ORM syntax for min order quantity query Use frappe.get_all instead of raw SQL with manual string formatting to fetch min_order_qty. This improves code readability and leverages the framework's built-in database abstraction. * chore: fix formatting * chore: fix formatting * chore: fix formatting by adding a space
This commit is contained in:
@@ -293,15 +293,14 @@ class PurchaseOrder(BuyingController):
|
|||||||
self.party_account_currency = get_party_account_currency("Supplier", self.supplier, self.company)
|
self.party_account_currency = get_party_account_currency("Supplier", self.supplier, self.company)
|
||||||
|
|
||||||
def validate_minimum_order_qty(self):
|
def validate_minimum_order_qty(self):
|
||||||
|
"""Check if total ordered quantities meet the Item's minimum order requirement."""
|
||||||
if not self.get("items"):
|
if not self.get("items"):
|
||||||
return
|
return
|
||||||
items = list(set(d.item_code for d in self.get("items")))
|
items = list(set(d.item_code for d in self.get("items")))
|
||||||
|
|
||||||
itemwise_min_order_qty = frappe._dict(
|
itemwise_min_order_qty = frappe._dict(
|
||||||
frappe.db.sql(
|
frappe.get_all(
|
||||||
"""select name, min_order_qty
|
"Item", fields=["name", "min_order_qty"], filters={"name": ["in", items]}, as_list=True
|
||||||
from tabItem where name in ({})""".format(", ".join(["%s"] * len(items))),
|
|
||||||
items,
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user