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
(cherry picked from commit b75b00f)

# Conflicts:
#	erpnext/manufacturing/doctype/bom/bom.py
#	erpnext/manufacturing/doctype/bom/test_bom.py
  • Loading branch information
rohitwaghchaure authored and mergify[bot] committed May 30, 2022
1 parent 7767dc1 commit 38fc7dd
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 4 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
25 changes: 25 additions & 0 deletions erpnext/manufacturing/doctype/bom/bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def set_bom_material_details(self):
for item in self.get("items"):
self.validate_bom_currency(item)

<<<<<<< HEAD
ret = self.get_bom_material_detail(
{
"company": self.company,
Expand All @@ -265,6 +266,27 @@ def set_bom_material_details(self):
"sourced_by_supplier": item.sourced_by_supplier,
}
)
=======
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,
"item_name": item.item_name,
"bom_no": item.bom_no,
"stock_qty": item.stock_qty,
"include_item_in_manufacturing": item.include_item_in_manufacturing,
"qty": item.qty,
"uom": item.uom,
"stock_uom": item.stock_uom,
"conversion_factor": item.conversion_factor,
"sourced_by_supplier": item.sourced_by_supplier,
"do_not_explode": item.do_not_explode
})

>>>>>>> b75b00fefc (feat: provision to exclude exploded items in the BOM (#29450))
for r in ret:
if not item.get(r):
item.set(r, ret[r])
Expand Down Expand Up @@ -321,6 +343,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
20 changes: 20 additions & 0 deletions erpnext/manufacturing/doctype/bom/test_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ def test_bom_item_query(self):
)
self.assertTrue(0 < len(filtered) <= 3, msg="Item filtering showing excessive results")

<<<<<<< HEAD
def test_valid_transfer_defaults(self):
bom_with_op = frappe.db.get_value(
"BOM", {"item": "_Test FG Item 2", "with_operations": 1, "is_active": 1}
Expand Down Expand Up @@ -501,6 +502,25 @@ def test_bom_pricing_based_on_lpp(self):
bom.submit()
self.assertEqual(bom.items[0].rate, 42)

=======
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()
>>>>>>> b75b00fefc (feat: provision to exclude exploded items in the BOM (#29450))

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 38fc7dd

Please sign in to comment.