refactor(sales_order): Replace SQL with ORM in validate_for_items (#55199)

This commit is contained in:
Loic Oberle
2026-05-23 08:13:50 +02:00
committed by GitHub
parent 2d2b45f270
commit 78894f7c78

View File

@@ -368,16 +368,22 @@ class SalesOrder(SellingController):
) )
def validate_for_items(self): def validate_for_items(self):
for d in self.get("items"): item_warehouse_pairs = [
# used for production plan (d.item_code, d.warehouse) for d in self.get("items") if d.item_code and d.warehouse
d.transaction_date = self.transaction_date ]
tot_avail_qty = frappe.db.sql( bin_data = {}
"select projected_qty from `tabBin` \ if item_warehouse_pairs:
where item_code = %s and warehouse = %s", bins = frappe.get_all(
(d.item_code, d.warehouse), "Bin",
fields=["item_code", "warehouse", "projected_qty"],
filters={"item_code": ["in", [p[0] for p in item_warehouse_pairs]]},
) )
d.projected_qty = tot_avail_qty and flt(tot_avail_qty[0][0]) or 0 bin_data = {(b.item_code, b.warehouse): flt(b.projected_qty) for b in bins}
for d in self.get("items"):
d.transaction_date = self.transaction_date
d.projected_qty = bin_data.get((d.item_code, d.warehouse), 0.0)
def product_bundle_has_stock_item(self, product_bundle): def product_bundle_has_stock_item(self, product_bundle):
"""Returns true if product bundle has stock item""" """Returns true if product bundle has stock item"""