fix: purchase to Stock UOM conversion on Production Plan #28570
fix: purchase to Stock UOM conversion on Production Plan
diff --git a/erpnext/manufacturing/doctype/production_plan/production_plan.py b/erpnext/manufacturing/doctype/production_plan/production_plan.py
index 7cec7f5..4d31f41 100644
--- a/erpnext/manufacturing/doctype/production_plan/production_plan.py
+++ b/erpnext/manufacturing/doctype/production_plan/production_plan.py
@@ -969,7 +969,25 @@
new_mr_items.append(new_dict)
if required_qty:
+ stock_uom, purchase_uom = frappe.db.get_value(
+ 'Item',
+ item['item_code'],
+ ['stock_uom', 'purchase_uom']
+ )
+
+ if purchase_uom != stock_uom and purchase_uom == item['uom']:
+ conversion_factor = get_uom_conversion_factor(item['item_code'], item['uom'])
+ if not (conversion_factor or frappe.flags.show_qty_in_stock_uom):
+ frappe.throw(_("UOM Conversion factor ({0} -> {1}) not found for item: {2}")
+ .format(purchase_uom, stock_uom, item['item_code']))
+
+ required_qty = required_qty / conversion_factor
+
+ if frappe.db.get_value("UOM", purchase_uom, "must_be_whole_number"):
+ required_qty = ceil(required_qty)
+
item["quantity"] = required_qty
+
new_mr_items.append(item)
@frappe.whitelist()