mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-07 15:25:19 +00:00
fix: don't allow BOM's item code at any level of child items (#27175)
* fix: don't allow BOM's item code at any level of child items (#27157)
* refactor: bom recursion checking
* fix: dont allow bom recursion
if same item_code is added in child items at any level, it shouldn't be allowed.
* test: add test for bom recursion
* test: fix broken prodplan test using recursive bom
* test: fix recursive bom in tests
(cherry picked from commit c07dce940e)
# Conflicts:
# erpnext/manufacturing/doctype/bom/test_bom.py
# erpnext/manufacturing/doctype/production_plan/test_production_plan.py
# erpnext/manufacturing/doctype/work_order/test_work_order.py
* fix: resolve conflicts
[skip ci]
* fix: conflicts
[skip ci]
* fix: resolve conflicts
Co-authored-by: Ankush Menat <ankush@iwebnotes.com>
This commit is contained in:
@@ -414,25 +414,29 @@ class BOM(WebsiteGenerator):
|
||||
frappe.throw(_("Quantity required for Item {0} in row {1}").format(m.item_code, m.idx))
|
||||
check_list.append(m)
|
||||
|
||||
def check_recursion(self, bom_list=[]):
|
||||
def check_recursion(self, bom_list=None):
|
||||
""" Check whether recursion occurs in any bom"""
|
||||
def _throw_error(bom_name):
|
||||
frappe.throw(_("BOM recursion: {0} cannot be parent or child of {0}").format(bom_name))
|
||||
|
||||
bom_list = self.traverse_tree()
|
||||
bom_nos = frappe.get_all('BOM Item', fields=["bom_no"],
|
||||
filters={'parent': ('in', bom_list), 'parenttype': 'BOM'})
|
||||
child_items = frappe.get_all('BOM Item', fields=["bom_no", "item_code"],
|
||||
filters={'parent': ('in', bom_list), 'parenttype': 'BOM'}) or []
|
||||
|
||||
raise_exception = False
|
||||
if bom_nos and self.name in [d.bom_no for d in bom_nos]:
|
||||
raise_exception = True
|
||||
child_bom = {d.bom_no for d in child_items}
|
||||
child_items_codes = {d.item_code for d in child_items}
|
||||
|
||||
if not raise_exception:
|
||||
bom_nos = frappe.get_all('BOM Item', fields=["parent"],
|
||||
filters={'bom_no': self.name, 'parenttype': 'BOM'})
|
||||
if self.name in child_bom:
|
||||
_throw_error(self.name)
|
||||
|
||||
if self.name in [d.parent for d in bom_nos]:
|
||||
raise_exception = True
|
||||
if self.item in child_items_codes:
|
||||
_throw_error(self.item)
|
||||
|
||||
if raise_exception:
|
||||
frappe.throw(_("BOM recursion: {0} cannot be parent or child of {1}").format(self.name, self.name))
|
||||
bom_nos = frappe.get_all('BOM Item', fields=["parent"],
|
||||
filters={'bom_no': self.name, 'parenttype': 'BOM'}) or []
|
||||
|
||||
if self.name in {d.parent for d in bom_nos}:
|
||||
_throw_error(self.name)
|
||||
|
||||
def update_cost_and_exploded_items(self, bom_list=[]):
|
||||
bom_list = self.traverse_tree(bom_list)
|
||||
|
||||
@@ -198,6 +198,7 @@ class TestProductionPlan(unittest.TestCase):
|
||||
pln.cancel()
|
||||
frappe.delete_doc("Production Plan", pln.name)
|
||||
|
||||
|
||||
def create_production_plan(**args):
|
||||
args = frappe._dict(args)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user