Skip to content

Commit

Permalink
feat: provision to exclude exploded items in the BOM (#29450)
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure authored Jan 27, 2022
1 parent 0cb965f commit b75b00f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 5 deletions.
12 changes: 10 additions & 2 deletions erpnext/manufacturing/doctype/bom/bom.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ frappe.ui.form.on("BOM", {
});
});

if (has_template_rm) {
if (has_template_rm && has_template_rm.length) {
dialog.fields_dict.items.grid.refresh();
}
},
Expand Down Expand Up @@ -467,7 +467,8 @@ var get_bom_material_detail = function(doc, cdt, cdn, scrap_items) {
"uom": d.uom,
"stock_uom": d.stock_uom,
"conversion_factor": d.conversion_factor,
"sourced_by_supplier": d.sourced_by_supplier
"sourced_by_supplier": d.sourced_by_supplier,
"do_not_explode": d.do_not_explode
},
callback: function(r) {
d = locals[cdt][cdn];
Expand Down Expand Up @@ -640,6 +641,13 @@ frappe.ui.form.on("BOM Operation", "workstation", function(frm, cdt, cdn) {
});
});

frappe.ui.form.on("BOM Item", {
do_not_explode: function(frm, cdt, cdn) {
get_bom_material_detail(frm.doc, cdt, cdn, false);
}
})


frappe.ui.form.on("BOM Item", "qty", function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
d.stock_qty = d.qty * d.conversion_factor;
Expand Down
11 changes: 10 additions & 1 deletion erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ def set_bom_material_details(self):
for item in self.get("items"):
self.validate_bom_currency(item)

item.bom_no = ''
if not item.do_not_explode:
item.bom_no = item.bom_no

ret = self.get_bom_material_detail({
"company": self.company,
"item_code": item.item_code,
Expand All @@ -214,8 +218,10 @@ def set_bom_material_details(self):
"uom": item.uom,
"stock_uom": item.stock_uom,
"conversion_factor": item.conversion_factor,
"sourced_by_supplier": item.sourced_by_supplier
"sourced_by_supplier": item.sourced_by_supplier,
"do_not_explode": item.do_not_explode
})

for r in ret:
if not item.get(r):
item.set(r, ret[r])
Expand Down Expand Up @@ -267,6 +273,9 @@ def get_bom_material_detail(self, args=None):
'sourced_by_supplier' : args.get('sourced_by_supplier', 0)
}

if args.get('do_not_explode'):
ret_item['bom_no'] = ''

return ret_item

def validate_bom_currency(self, item):
Expand Down
17 changes: 17 additions & 0 deletions erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,23 @@ def test_bom_item_query(self):
self.assertNotEqual(len(test_items), len(filtered), msg="Item filtering showing excessive results")
self.assertTrue(0 < len(filtered) <= 3, msg="Item filtering showing excessive results")

def test_exclude_exploded_items_from_bom(self):
bom_no = get_default_bom()
new_bom = frappe.copy_doc(frappe.get_doc('BOM', bom_no))
for row in new_bom.items:
if row.item_code == '_Test Item Home Desktop Manufactured':
self.assertTrue(row.bom_no)
row.do_not_explode = True

new_bom.docstatus = 0
new_bom.save()
new_bom.load_from_db()

for row in new_bom.items:
if row.item_code == '_Test Item Home Desktop Manufactured' and row.do_not_explode:
self.assertFalse(row.bom_no)

new_bom.delete()

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
13 changes: 11 additions & 2 deletions erpnext/manufacturing/doctype/bom_item/bom_item.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"item_name",
"operation",
"column_break_3",
"do_not_explode",
"bom_no",
"source_warehouse",
"allow_alternative_item",
Expand Down Expand Up @@ -73,6 +74,7 @@
"fieldtype": "Column Break"
},
{
"depends_on": "eval:!doc.do_not_explode",
"fieldname": "bom_no",
"fieldtype": "Link",
"in_filter": 1,
Expand Down Expand Up @@ -284,18 +286,25 @@
"fieldname": "sourced_by_supplier",
"fieldtype": "Check",
"label": "Sourced by Supplier"
},
{
"default": "0",
"fieldname": "do_not_explode",
"fieldtype": "Check",
"label": "Do Not Explode"
}
],
"idx": 1,
"index_web_pages_for_search": 1,
"istable": 1,
"links": [],
"modified": "2020-10-08 14:19:37.563300",
"modified": "2022-01-24 16:57:57.020232",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "BOM Item",
"owner": "Administrator",
"permissions": [],
"sort_field": "modified",
"sort_order": "DESC"
"sort_order": "DESC",
"states": []
}

0 comments on commit b75b00f

Please sign in to comment.