Skip to content

Commit

Permalink
fix: incorrect stock UOM for BOM raw materials (#44528)
Browse files Browse the repository at this point in the history
fix: incorrect stock uom for BOM raw materials
  • Loading branch information
rohitwaghchaure authored Dec 5, 2024
1 parent 707d8ed commit 5413cf9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
18 changes: 18 additions & 0 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,24 @@ def validate(self):
self.update_cost(update_parent=False, from_child_bom=True, update_hour_rate=False, save=False)
self.set_process_loss_qty()
self.validate_scrap_items()
self.set_default_uom()

def set_default_uom(self):
if not self.get("items"):
return

item_wise_uom = frappe._dict(
frappe.get_all(
"Item",
filters={"name": ("in", [item.item_code for item in self.items])},
fields=["name", "stock_uom"],
as_list=1,
)
)

for row in self.get("items"):
if row.stock_uom != item_wise_uom.get(row.item_code):
row.stock_uom = item_wise_uom.get(row.item_code)

def get_context(self, context):
context.parents = [{"name": "boms", "title": _("All BOMs")}]
Expand Down
20 changes: 20 additions & 0 deletions erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,6 +763,26 @@ def test_do_not_include_manufacturing_and_fixed_items(self):
self.assertTrue("_Test RM Item 2 Fixed Asset Item" not in items)
self.assertTrue("_Test RM Item 3 Manufacture Item" in items)

def test_bom_raw_materials_stock_uom(self):
rm_item = make_item(
properties={"is_stock_item": 1, "valuation_rate": 1000.0, "stock_uom": "Nos"}
).name
fg_item = make_item(properties={"is_stock_item": 1}).name

from erpnext.manufacturing.doctype.production_plan.test_production_plan import make_bom

bom = make_bom(item=fg_item, raw_materials=[rm_item], do_not_submit=True)
for row in bom.items:
self.assertEqual(row.stock_uom, "Nos")

frappe.db.set_value("Item", rm_item, "stock_uom", "Kg")

bom.items[0].qty = 2
bom.save()

for row in bom.items:
self.assertEqual(row.stock_uom, "Kg")


def get_default_bom(item_code="_Test FG Item 2"):
return frappe.db.get_value("BOM", {"item": item_code, "is_active": 1, "is_default": 1})
Expand Down

0 comments on commit 5413cf9

Please sign in to comment.