Skip to content

Commit

Permalink
fix: do not make MR against raw materials of available sub assemblies (
Browse files Browse the repository at this point in the history
…#40085)

(cherry picked from commit 4c9048f)
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed Feb 24, 2024
1 parent 2b01b10 commit 5535eea
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 13 deletions.
24 changes: 11 additions & 13 deletions erpnext/manufacturing/doctype/production_plan/production_plan.py
Original file line number Diff line number Diff line change
Expand Up @@ -1430,19 +1430,17 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d
frappe.throw(_("For row {0}: Enter Planned Qty").format(data.get("idx")))

if bom_no:
if (
data.get("include_exploded_items")
and doc.get("sub_assembly_items")
and doc.get("skip_available_sub_assembly_item")
):
item_details = get_raw_materials_of_sub_assembly_items(
item_details,
company,
bom_no,
include_non_stock_items,
sub_assembly_items,
planned_qty=planned_qty,
)
if data.get("include_exploded_items") and doc.get("skip_available_sub_assembly_item"):
item_details = {}
if doc.get("sub_assembly_items"):
item_details = get_raw_materials_of_sub_assembly_items(
item_details,
company,
bom_no,
include_non_stock_items,
sub_assembly_items,
planned_qty=planned_qty,
)

elif data.get("include_exploded_items") and include_subcontracted_items:
# fetch exploded items from BOM
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,35 @@ def test_skip_available_qty_for_sub_assembly_items(self):
if row.item_code == "SubAssembly2 For SUB Test":
self.assertEqual(row.quantity, 10)

def test_sub_assembly_and_their_raw_materials_exists(self):
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom

bom_tree = {
"FG1 For SUB Test": {
"SAB1 For SUB Test": {"CP1 For SUB Test": {}},
"SAB2 For SUB Test": {},
}
}

parent_bom = create_nested_bom(bom_tree, prefix="")
for item in ["SAB1 For SUB Test", "SAB2 For SUB Test"]:
make_stock_entry(item_code=item, qty=10, rate=100, target="_Test Warehouse - _TC")

plan = create_production_plan(
item_code=parent_bom.item,
planned_qty=10,
ignore_existing_ordered_qty=1,
do_not_submit=1,
skip_available_sub_assembly_item=1,
warehouse="_Test Warehouse - _TC",
)

items = get_items_for_material_requests(
plan.as_dict(), warehouses=[{"warehouse": "_Test Warehouse - _TC"}]
)

self.assertFalse(items)

def test_transfer_and_purchase_mrp_for_purchase_uom(self):
from erpnext.manufacturing.doctype.bom.test_bom import create_nested_bom
from erpnext.stock.doctype.warehouse.test_warehouse import create_warehouse
Expand Down

0 comments on commit 5535eea

Please sign in to comment.