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):
for d in self.get("items"):
# used for production plan
d.transaction_date = self.transaction_date
item_warehouse_pairs = [
(d.item_code, d.warehouse) for d in self.get("items") if d.item_code and d.warehouse
]
tot_avail_qty = frappe.db.sql(
"select projected_qty from `tabBin` \
where item_code = %s and warehouse = %s",
(d.item_code, d.warehouse),
bin_data = {}
if item_warehouse_pairs:
bins = frappe.get_all(
"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):
"""Returns true if product bundle has stock item"""