mirror of
https://github.com/frappe/erpnext.git
synced 2026-04-21 23:58:30 +00:00
fix: enhance sub-assembly item handling in raw material request calculations
(cherry picked from commit f912c8419a)
# Conflicts:
# erpnext/manufacturing/doctype/production_plan/production_plan.py
This commit is contained in:
@@ -1543,6 +1543,7 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d
|
|||||||
include_safety_stock = doc.get("include_safety_stock")
|
include_safety_stock = doc.get("include_safety_stock")
|
||||||
|
|
||||||
so_item_details = frappe._dict()
|
so_item_details = frappe._dict()
|
||||||
|
existing_sub_assembly_items = set()
|
||||||
|
|
||||||
sub_assembly_items = defaultdict(int)
|
sub_assembly_items = defaultdict(int)
|
||||||
if doc.get("skip_available_sub_assembly_item") and doc.get("sub_assembly_items"):
|
if doc.get("skip_available_sub_assembly_item") and doc.get("sub_assembly_items"):
|
||||||
@@ -1572,6 +1573,7 @@ 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")))
|
frappe.throw(_("For row {0}: Enter Planned Qty").format(data.get("idx")))
|
||||||
|
|
||||||
if bom_no:
|
if bom_no:
|
||||||
|
<<<<<<< HEAD
|
||||||
if data.get("include_exploded_items") and doc.get("skip_available_sub_assembly_item"):
|
if data.get("include_exploded_items") and doc.get("skip_available_sub_assembly_item"):
|
||||||
item_details = {}
|
item_details = {}
|
||||||
if doc.get("sub_assembly_items"):
|
if doc.get("sub_assembly_items"):
|
||||||
@@ -1584,6 +1586,22 @@ def get_items_for_material_requests(doc, warehouses=None, get_parent_warehouse_d
|
|||||||
sub_assembly_items,
|
sub_assembly_items,
|
||||||
planned_qty=planned_qty,
|
planned_qty=planned_qty,
|
||||||
)
|
)
|
||||||
|
=======
|
||||||
|
if (
|
||||||
|
data.get("include_exploded_items")
|
||||||
|
and doc.get("skip_available_sub_assembly_item")
|
||||||
|
and doc.get("sub_assembly_items")
|
||||||
|
):
|
||||||
|
item_details = get_raw_materials_of_sub_assembly_items(
|
||||||
|
existing_sub_assembly_items,
|
||||||
|
item_details,
|
||||||
|
company,
|
||||||
|
bom_no,
|
||||||
|
include_non_stock_items,
|
||||||
|
sub_assembly_items,
|
||||||
|
planned_qty=planned_qty,
|
||||||
|
)
|
||||||
|
>>>>>>> f912c8419a (fix: enhance sub-assembly item handling in raw material request calculations)
|
||||||
|
|
||||||
elif data.get("include_exploded_items") and include_subcontracted_items:
|
elif data.get("include_exploded_items") and include_subcontracted_items:
|
||||||
# fetch exploded items from BOM
|
# fetch exploded items from BOM
|
||||||
@@ -1955,6 +1973,7 @@ def get_raw_materials_of_sub_assembly_items(
|
|||||||
sub_assembly_items,
|
sub_assembly_items,
|
||||||
planned_qty=planned_qty,
|
planned_qty=planned_qty,
|
||||||
)
|
)
|
||||||
|
existing_sub_assembly_items.add(item.item_code)
|
||||||
else:
|
else:
|
||||||
if not item.conversion_factor and item.purchase_uom:
|
if not item.conversion_factor and item.purchase_uom:
|
||||||
item.conversion_factor = get_uom_conversion_factor(item.item_code, item.purchase_uom)
|
item.conversion_factor = get_uom_conversion_factor(item.item_code, item.purchase_uom)
|
||||||
|
|||||||
@@ -1637,11 +1637,17 @@ class TestProductionPlan(FrappeTestCase):
|
|||||||
|
|
||||||
def test_calculation_of_sub_assembly_items(self):
|
def test_calculation_of_sub_assembly_items(self):
|
||||||
make_item("Sub Assembly Item ", properties={"is_stock_item": 1})
|
make_item("Sub Assembly Item ", properties={"is_stock_item": 1})
|
||||||
|
make_item("Sub Assembly Item 2", properties={"is_stock_item": 1})
|
||||||
make_item("RM Item 1", properties={"is_stock_item": 1})
|
make_item("RM Item 1", properties={"is_stock_item": 1})
|
||||||
make_item("RM Item 2", properties={"is_stock_item": 1})
|
make_item("RM Item 2", properties={"is_stock_item": 1})
|
||||||
|
make_item("_Test FG Item 3", properties={"is_stock_item": 1})
|
||||||
|
make_item("_Test FG Item 4", properties={"is_stock_item": 1})
|
||||||
make_bom(item="Sub Assembly Item", raw_materials=["RM Item 1", "RM Item 2"])
|
make_bom(item="Sub Assembly Item", raw_materials=["RM Item 1", "RM Item 2"])
|
||||||
|
make_bom(item="Sub Assembly Item 2", raw_materials=["RM Item 2"])
|
||||||
make_bom(item="_Test FG Item", raw_materials=["Sub Assembly Item", "RM Item 1"])
|
make_bom(item="_Test FG Item", raw_materials=["Sub Assembly Item", "RM Item 1"])
|
||||||
make_bom(item="_Test FG Item 2", raw_materials=["Sub Assembly Item"])
|
make_bom(item="_Test FG Item 2", raw_materials=["Sub Assembly Item"])
|
||||||
|
make_bom(item="_Test FG Item 3", raw_materials=["RM Item 1"])
|
||||||
|
make_bom(item="_Test FG Item 4", raw_materials=["Sub Assembly Item 2"])
|
||||||
|
|
||||||
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
|
||||||
|
|
||||||
@@ -1677,12 +1683,39 @@ class TestProductionPlan(FrappeTestCase):
|
|||||||
"warehouse": "_Test Warehouse - _TC",
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
# Assembly item with similar RM item
|
||||||
|
plan.append(
|
||||||
|
"po_items",
|
||||||
|
{
|
||||||
|
"use_multi_level_bom": 1,
|
||||||
|
"item_code": "_Test FG Item 3",
|
||||||
|
"bom_no": frappe.db.get_value("Item", "_Test FG Item 3", "default_bom"),
|
||||||
|
"planned_qty": 10,
|
||||||
|
"planned_start_date": now_datetime(),
|
||||||
|
"stock_uom": "Nos",
|
||||||
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
# Sub-assembly item with similar RM item
|
||||||
|
plan.append(
|
||||||
|
"po_items",
|
||||||
|
{
|
||||||
|
"use_multi_level_bom": 1,
|
||||||
|
"item_code": "_Test FG Item 4",
|
||||||
|
"bom_no": frappe.db.get_value("Item", "_Test FG Item 4", "default_bom"),
|
||||||
|
"planned_qty": 10,
|
||||||
|
"planned_start_date": now_datetime(),
|
||||||
|
"stock_uom": "Nos",
|
||||||
|
"warehouse": "_Test Warehouse - _TC",
|
||||||
|
},
|
||||||
|
)
|
||||||
plan.save()
|
plan.save()
|
||||||
|
|
||||||
plan.get_sub_assembly_items()
|
plan.get_sub_assembly_items()
|
||||||
|
|
||||||
self.assertEqual(plan.sub_assembly_items[0].qty, 20)
|
self.assertEqual(plan.sub_assembly_items[0].qty, 20) # Sub Assembly For FG 1
|
||||||
self.assertEqual(plan.sub_assembly_items[1].qty, 50)
|
self.assertEqual(plan.sub_assembly_items[1].qty, 50) # Sub Assembly For FG 2
|
||||||
|
self.assertEqual(plan.sub_assembly_items[2].qty, 10) # Sub Assembly For FG 4
|
||||||
|
|
||||||
from erpnext.manufacturing.doctype.production_plan.production_plan import (
|
from erpnext.manufacturing.doctype.production_plan.production_plan import (
|
||||||
get_items_for_material_requests,
|
get_items_for_material_requests,
|
||||||
@@ -1690,8 +1723,11 @@ class TestProductionPlan(FrappeTestCase):
|
|||||||
|
|
||||||
mr_items = get_items_for_material_requests(plan.as_dict())
|
mr_items = get_items_for_material_requests(plan.as_dict())
|
||||||
|
|
||||||
self.assertEqual(mr_items[0].get("quantity"), 80)
|
# RM Item 1 (FG1 (100 + 100) + FG2 (50) + FG3 (10) - 90 in stock - 80 sub assembly stock)
|
||||||
self.assertEqual(mr_items[1].get("quantity"), 70)
|
self.assertEqual(mr_items[0].get("quantity"), 90)
|
||||||
|
|
||||||
|
# RM Item 2 (FG1 (100) + FG2 (50) + FG4 (10) - 80 sub assembly stock)
|
||||||
|
self.assertEqual(mr_items[1].get("quantity"), 80)
|
||||||
|
|
||||||
def test_production_plan_for_partial_sub_assembly_items(self):
|
def test_production_plan_for_partial_sub_assembly_items(self):
|
||||||
from erpnext.controllers.status_updater import OverAllowanceError
|
from erpnext.controllers.status_updater import OverAllowanceError
|
||||||
|
|||||||
Reference in New Issue
Block a user