From 7cf1a1d84b7e5bbcabe37478cbcbe18e7eef8906 Mon Sep 17 00:00:00 2001 From: Kanchan Chauhan Date: Thu, 16 Mar 2017 17:09:37 +0530 Subject: [PATCH] Project filter in BOM selection in Production Order --- .../production_order/production_order.js | 9 ++- .../production_order/production_order.json | 67 ++++++++++--------- .../production_order/production_order.py | 13 +++- 3 files changed, 53 insertions(+), 36 deletions(-) diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js index 7d42f41895..836024c3b0 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.js +++ b/erpnext/manufacturing/doctype/production_order/production_order.js @@ -213,7 +213,10 @@ $.extend(cur_frm.cscript, { 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 @@ $.extend(cur_frm.cscript, { }); }, + 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 f9b99abedc..c1ea17db26 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:", @@ -134,6 +135,37 @@ "set_only_once": 0, "unique": 0 }, + { + "allow_on_submit": 0, + "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, @@ -1122,37 +1154,6 @@ "unique": 0, "width": "50%" }, - { - "allow_on_submit": 0, - "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, @@ -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 af9fff1374..907a4b324a 100644 --- a/erpnext/manufacturing/doctype/production_order/production_order.py +++ b/erpnext/manufacturing/doctype/production_order/production_order.py @@ -448,7 +448,7 @@ class ProductionOrder(Document): @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 @@ def get_item_details(item): 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"]))