Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getting scrap items from sub assemblies by fetching scrap items for parent BOM #42928

Open
wants to merge 5 commits into
base: version-15-hotfix
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,9 @@ def get_scrap_items_from_sub_assemblies(bom_no, company, qty, scrap_items=None):
fields=["bom_no", "qty"],
order_by="idx asc",
)
# fetch Scrap Items for Parent Bom
items = get_bom_items_as_dict(bom_no, company, qty=qty, fetch_exploded=0, fetch_scrap_items=1)
scrap_items.update(items)

for row in bom_items:
if not row.bom_no:
Expand Down
13 changes: 13 additions & 0 deletions erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,19 @@ 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_get_scrap_items_from_sub_assemblies(self):
from erpnext.manufacturing.doctype.bom.bom import get_scrap_items_from_sub_assemblies

bom = frappe.copy_doc(test_records[1])
bom.insert(ignore_mandatory=True)

bom_scraped_items = [i.get("item_code") for i in bom.get("scrap_items", [])]

# get scrapted items for parent bom
scraped_items = get_scrap_items_from_sub_assemblies(bom.name, bom.company, 2, None)
for item_code in scraped_items.keys():
self.assertIn(item_code, bom_scraped_items, f"Item {item_code} not found in BOM scrap 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"}
Expand Down
Loading