Project filter in BOM selection in Production Order
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js
index 7d42f41..836024c 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order.js
@@ -213,7 +213,10 @@
production_item: function(doc) {
frappe.call({
method: "erpnext.manufacturing.doctype.production_order.production_order.get_item_details",
- args: { item: doc.production_item },
+ args: {
+ item: doc.production_item,
+ project: doc.project
+ },
callback: function(r) {
$.each(["description", "stock_uom", "bom_no"], function(i, field) {
cur_frm.set_value(field, r.message[field]);
@@ -226,6 +229,10 @@
});
},
+ project: function(doc) {
+ cur_frm.cscript.production_item(doc)
+ },
+
make_se: function(purpose) {
var me = this;
var max = (purpose === "Manufacture") ?
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.json b/erpnext/manufacturing/doctype/production_order/production_order.json
index f9b99ab..c1ea17d 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.json
+++ b/erpnext/manufacturing/doctype/production_order/production_order.json
@@ -1,5 +1,6 @@
{
"allow_copy": 0,
+ "allow_guest_to_view": 0,
"allow_import": 1,
"allow_rename": 0,
"autoname": "naming_series:",
@@ -139,6 +140,37 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
+ "fieldname": "project",
+ "fieldtype": "Link",
+ "hidden": 0,
+ "ignore_user_permissions": 0,
+ "ignore_xss_filter": 0,
+ "in_filter": 0,
+ "in_global_search": 0,
+ "in_list_view": 0,
+ "in_standard_filter": 0,
+ "label": "Project",
+ "length": 0,
+ "no_copy": 0,
+ "oldfieldname": "project",
+ "oldfieldtype": "Link",
+ "options": "Project",
+ "permlevel": 0,
+ "print_hide": 0,
+ "print_hide_if_no_value": 0,
+ "read_only": 0,
+ "remember_last_selected_value": 0,
+ "report_hide": 0,
+ "reqd": 0,
+ "search_index": 0,
+ "set_only_once": 0,
+ "unique": 0
+ },
+ {
+ "allow_on_submit": 0,
+ "bold": 0,
+ "collapsible": 0,
+ "columns": 0,
"depends_on": "",
"description": "",
"fieldname": "bom_no",
@@ -1127,37 +1159,6 @@
"bold": 0,
"collapsible": 0,
"columns": 0,
- "fieldname": "project",
- "fieldtype": "Link",
- "hidden": 0,
- "ignore_user_permissions": 0,
- "ignore_xss_filter": 0,
- "in_filter": 0,
- "in_global_search": 0,
- "in_list_view": 0,
- "in_standard_filter": 0,
- "label": "Project",
- "length": 0,
- "no_copy": 0,
- "oldfieldname": "project",
- "oldfieldtype": "Link",
- "options": "Project",
- "permlevel": 0,
- "print_hide": 0,
- "print_hide_if_no_value": 0,
- "read_only": 0,
- "remember_last_selected_value": 0,
- "report_hide": 0,
- "reqd": 0,
- "search_index": 0,
- "set_only_once": 0,
- "unique": 0
- },
- {
- "allow_on_submit": 0,
- "bold": 0,
- "collapsible": 0,
- "columns": 0,
"description": "Manufacture against Material Request",
"fieldname": "material_request",
"fieldtype": "Link",
@@ -1275,18 +1276,18 @@
"unique": 0
}
],
+ "has_web_view": 0,
"hide_heading": 0,
"hide_toolbar": 0,
"icon": "fa fa-cogs",
"idx": 1,
"image_view": 0,
"in_create": 0,
- "in_dialog": 0,
"is_submittable": 1,
"issingle": 0,
"istable": 0,
"max_attachments": 0,
- "modified": "2017-02-17 17:26:47.310275",
+ "modified": "2017-03-16 16:24:16.773317",
"modified_by": "Administrator",
"module": "Manufacturing",
"name": "Production Order",
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index af9fff1..907a4b3 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -448,7 +448,7 @@
@frappe.whitelist()
-def get_item_details(item):
+def get_item_details(item, project = None):
res = frappe.db.sql("""select stock_uom, description
from `tabItem` where disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)
and name=%s""", (nowdate(), item), as_dict=1)
@@ -457,13 +457,22 @@
res = res[0]
- res["bom_no"] = frappe.db.get_value("BOM", filters={"item": item, "is_default": 1})
+ filters = {"item": item, "is_default": 1}
+
+ if project:
+ filters = {"item": item, "project": project}
+
+ res["bom_no"] = frappe.db.get_value("BOM", filters = filters)
+
if not res["bom_no"]:
variant_of= frappe.db.get_value("Item", item, "variant_of")
+
if variant_of:
res["bom_no"] = frappe.db.get_value("BOM", filters={"item": variant_of, "is_default": 1})
if not res["bom_no"]:
+ if project:
+ frappe.throw(_("Default BOM for {0} not found for Project {1}").format(item, project))
frappe.throw(_("Default BOM for {0} not found").format(item))
res.update(check_if_scrap_warehouse_mandatory(res["bom_no"]))