fix: compare ordered qty to min order qty at stock_qty precision

stock_qty is stored as raw qty * conversion_factor, so a UOM-converted
order for exactly the minimum (e.g. LB to Kg) produces values like
1999.999999131832 vs a min_order_qty of 2000 and blocks the Purchase
Order. Round both sides to the stock_qty field precision before
comparing, and show the rounded qty in the error message.
This commit is contained in:
Mihir Kandoi
2026-08-07 12:44:28 +05:30
parent 3f8b263014
commit 98b7407949

View File

@@ -310,12 +310,13 @@ class PurchaseOrder(BuyingController):
itemwise_qty.setdefault(d.item_code, 0)
itemwise_qty[d.item_code] += flt(d.stock_qty)
precision = self.items[0].precision("stock_qty")
for item_code, qty in itemwise_qty.items():
if flt(qty) < flt(itemwise_min_order_qty.get(item_code)):
if flt(qty, precision) < flt(itemwise_min_order_qty.get(item_code), precision):
frappe.throw(
_(
"Item {0}: Ordered qty {1} cannot be less than minimum order qty {2} (defined in Item)."
).format(item_code, qty, itemwise_min_order_qty.get(item_code))
).format(item_code, flt(qty, precision), itemwise_min_order_qty.get(item_code))
)
def get_schedule_dates(self):