From 41acbff9594de540d9e6e240cdcbfedaeb216458 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 20 Jan 2015 17:39:46 +0530 Subject: [PATCH 1/2] item name added to BOM --- erpnext/manufacturing/doctype/bom/bom.js | 1 + erpnext/manufacturing/doctype/bom/bom.json | 49 ++-- erpnext/manufacturing/doctype/bom/bom.py | 12 +- .../bom_explosion_item.json | 51 +++- .../doctype/bom_item/bom_item.json | 244 +++++++++--------- erpnext/patches.txt | 1 + .../patches/v5_0/update_item_name_in_bom.py | 12 + 7 files changed, 215 insertions(+), 155 deletions(-) create mode 100644 erpnext/patches/v5_0/update_item_name_in_bom.py diff --git a/erpnext/manufacturing/doctype/bom/bom.js b/erpnext/manufacturing/doctype/bom/bom.js index 4f78c4185a..7dedface67 100644 --- a/erpnext/manufacturing/doctype/bom/bom.js +++ b/erpnext/manufacturing/doctype/bom/bom.js @@ -61,6 +61,7 @@ cur_frm.cscript.operations_remove = function(){ } cur_frm.add_fetch("item", "description", "description"); +cur_frm.add_fetch("item", "item_name", "item_name"); cur_frm.add_fetch("item", "stock_uom", "uom"); diff --git a/erpnext/manufacturing/doctype/bom/bom.json b/erpnext/manufacturing/doctype/bom/bom.json index 7dac33ca2f..9d76d2fab5 100644 --- a/erpnext/manufacturing/doctype/bom/bom.json +++ b/erpnext/manufacturing/doctype/bom/bom.json @@ -21,6 +21,33 @@ "reqd": 1, "search_index": 1 }, + { + "fieldname": "item_name", + "fieldtype": "Data", + "label": "Item Name", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "rm_cost_as_per", + "fieldtype": "Select", + "label": "Rate Of Materials Based On", + "options": "Valuation Rate\nLast Purchase Rate\nPrice List", + "permlevel": 0 + }, + { + "depends_on": "eval:doc.rm_cost_as_per===\"Price List\"", + "fieldname": "buying_price_list", + "fieldtype": "Link", + "label": "Price List", + "options": "Price List", + "permlevel": 0 + }, + { + "fieldname": "cb0", + "fieldtype": "Column Break", + "permlevel": 0 + }, { "allow_on_submit": 1, "default": "1", @@ -47,11 +74,6 @@ "oldfieldtype": "Check", "permlevel": 0 }, - { - "fieldname": "cb0", - "fieldtype": "Column Break", - "permlevel": 0 - }, { "description": "Manage cost of operations", "fieldname": "with_operations", @@ -59,21 +81,6 @@ "label": "With Operations", "permlevel": 0 }, - { - "fieldname": "rm_cost_as_per", - "fieldtype": "Select", - "label": "Rate Of Materials Based On", - "options": "Valuation Rate\nLast Purchase Rate\nPrice List", - "permlevel": 0 - }, - { - "depends_on": "eval:doc.rm_cost_as_per===\"Price List\"", - "fieldname": "buying_price_list", - "fieldtype": "Link", - "label": "Price List", - "options": "Price List", - "permlevel": 0 - }, { "depends_on": "with_operations", "description": "Specify the operations, operating cost and give a unique Operation no to your operations.", @@ -245,7 +252,7 @@ "is_submittable": 1, "issingle": 0, "istable": 0, - "modified": "2015-01-07 11:11:07.047695", + "modified": "2015-01-20 11:54:43.042697", "modified_by": "Administrator", "module": "Manufacturing", "name": "BOM", diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py index 5c4a841fc5..4d079f42f0 100644 --- a/erpnext/manufacturing/doctype/bom/bom.py +++ b/erpnext/manufacturing/doctype/bom/bom.py @@ -53,7 +53,7 @@ class BOM(Document): self.manage_default_bom() def get_item_det(self, item_code): - item = frappe.db.sql("""select name, is_asset_item, is_purchase_item, + item = frappe.db.sql("""select name, item_name, is_asset_item, is_purchase_item, docstatus, description, is_sub_contracted_item, stock_uom, default_bom, last_purchase_rate from `tabItem` where name=%s""", item_code, as_dict = 1) @@ -69,7 +69,7 @@ class BOM(Document): def set_bom_material_details(self): for item in self.get("items"): - ret = self.get_bom_material_detail({"item_code": item.item_code, "bom_no": item.bom_no, + ret = self.get_bom_material_detail({"item_code": item.item_code, "item_name": item.item_name, "bom_no": item.bom_no, "qty": item.qty}) for r in ret: @@ -93,6 +93,7 @@ class BOM(Document): rate = self.get_rm_rate(args) ret_item = { + 'item_name' : item and args['item_name'] or '', 'description' : item and args['description'] or '', 'stock_uom' : item and args['stock_uom'] or '', 'bom_no' : args['bom_no'], @@ -203,9 +204,10 @@ class BOM(Document): if not item: frappe.throw(_("Item {0} does not exist in the system or has expired").format(self.item)) else: - ret = frappe.db.get_value("Item", self.item, ["description", "stock_uom"]) + ret = frappe.db.get_value("Item", self.item, ["description", "stock_uom", "item_name"]) self.description = ret[0] self.uom = ret[1] + self.item_name= ret[2] def validate_materials(self): """ Validate raw material entries """ @@ -313,6 +315,7 @@ class BOM(Document): else: self.add_to_cur_exploded_items(frappe._dict({ 'item_code' : d.item_code, + 'item_name' : d.item_name, 'description' : d.description, 'stock_uom' : d.stock_uom, 'qty' : flt(d.qty), @@ -328,7 +331,7 @@ class BOM(Document): def get_child_exploded_items(self, bom_no, qty): """ Add all items from Flat BOM of child BOM""" # Did not use qty_consumed_per_unit in the query, as it leads to rounding loss - child_fb_items = frappe.db.sql("""select bom_item.item_code, bom_item.description, + child_fb_items = frappe.db.sql("""select bom_item.item_code, bom_item.item_name, bom_item.description, bom_item.stock_uom, bom_item.qty, bom_item.rate, ifnull(bom_item.qty, 0 ) / ifnull(bom.quantity, 1) as qty_consumed_per_unit from `tabBOM Explosion Item` bom_item, tabBOM bom @@ -337,6 +340,7 @@ class BOM(Document): for d in child_fb_items: self.add_to_cur_exploded_items(frappe._dict({ 'item_code' : d['item_code'], + 'item_name' : d['item_name'], 'description' : d['description'], 'stock_uom' : d['stock_uom'], 'qty' : d['qty_consumed_per_unit']*qty, diff --git a/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json b/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json index 58b505da10..71b6da5f8d 100644 --- a/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json +++ b/erpnext/manufacturing/doctype/bom_explosion_item/bom_explosion_item.json @@ -16,6 +16,21 @@ "permlevel": 0, "read_only": 1 }, + { + "fieldname": "item_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Item Name", + "permlevel": 0, + "precision": "", + "read_only": 1 + }, + { + "fieldname": "column_break_2", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, { "fieldname": "description", "fieldtype": "Text", @@ -28,6 +43,12 @@ "read_only": 1, "width": "300px" }, + { + "fieldname": "section_break_4", + "fieldtype": "Section Break", + "permlevel": 0, + "precision": "" + }, { "fieldname": "qty", "fieldtype": "Float", @@ -50,16 +71,21 @@ "read_only": 1 }, { - "fieldname": "amount", - "fieldtype": "Currency", + "fieldname": "qty_consumed_per_unit", + "fieldtype": "Float", + "hidden": 0, "in_list_view": 1, - "label": "Amount", - "oldfieldname": "amount_as_per_sr", - "oldfieldtype": "Currency", - "options": "Company:company:default_currency", + "label": "Qty Consumed Per Unit", + "no_copy": 0, "permlevel": 0, "read_only": 1 }, + { + "fieldname": "column_break_8", + "fieldtype": "Column Break", + "permlevel": 0, + "precision": "" + }, { "fieldname": "stock_uom", "fieldtype": "Link", @@ -72,19 +98,20 @@ "read_only": 1 }, { - "fieldname": "qty_consumed_per_unit", - "fieldtype": "Float", - "hidden": 0, + "fieldname": "amount", + "fieldtype": "Currency", "in_list_view": 1, - "label": "Qty Consumed Per Unit", - "no_copy": 0, + "label": "Amount", + "oldfieldname": "amount_as_per_sr", + "oldfieldtype": "Currency", + "options": "Company:company:default_currency", "permlevel": 0, "read_only": 1 } ], "idx": 1, "istable": 1, - "modified": "2014-12-12 11:18:01.745641", + "modified": "2015-01-20 13:28:52.258152", "modified_by": "Administrator", "module": "Manufacturing", "name": "BOM Explosion Item", diff --git a/erpnext/manufacturing/doctype/bom_item/bom_item.json b/erpnext/manufacturing/doctype/bom_item/bom_item.json index 872f532559..79287ebb44 100644 --- a/erpnext/manufacturing/doctype/bom_item/bom_item.json +++ b/erpnext/manufacturing/doctype/bom_item/bom_item.json @@ -1,147 +1,155 @@ { - "creation": "2013-02-22 01:27:49", - "docstatus": 0, - "doctype": "DocType", + "creation": "2013-02-22 01:27:49", + "docstatus": 0, + "doctype": "DocType", "fields": [ { - "fieldname": "operation", - "fieldtype": "Select", - "in_list_view": 1, - "label": "Operation", - "oldfieldname": "operation_no", - "oldfieldtype": "Data", - "permlevel": 0, + "fieldname": "operation", + "fieldtype": "Select", + "in_list_view": 1, + "label": "Operation", + "oldfieldname": "operation_no", + "oldfieldtype": "Data", + "permlevel": 0, "reqd": 0 - }, + }, { - "fieldname": "item_code", - "fieldtype": "Link", - "in_filter": 1, - "in_list_view": 1, - "label": "Item Code", - "oldfieldname": "item_code", - "oldfieldtype": "Link", - "options": "Item", - "permlevel": 0, - "reqd": 1, + "fieldname": "item_code", + "fieldtype": "Link", + "in_filter": 1, + "in_list_view": 1, + "label": "Item Code", + "oldfieldname": "item_code", + "oldfieldtype": "Link", + "options": "Item", + "permlevel": 0, + "reqd": 1, "search_index": 1 - }, + }, { - "fieldname": "bom_no", - "fieldtype": "Link", - "in_filter": 1, - "in_list_view": 1, - "label": "BOM No", - "oldfieldname": "bom_no", - "oldfieldtype": "Link", - "options": "BOM", - "permlevel": 0, - "print_width": "150px", - "reqd": 0, - "search_index": 1, + "fieldname": "item_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Item Name", + "permlevel": 0, + "precision": "" + }, + { + "fieldname": "bom_no", + "fieldtype": "Link", + "in_filter": 1, + "in_list_view": 0, + "label": "BOM No", + "oldfieldname": "bom_no", + "oldfieldtype": "Link", + "options": "BOM", + "permlevel": 0, + "print_width": "150px", + "reqd": 0, + "search_index": 1, "width": "150px" - }, + }, { - "fieldname": "col_break1", - "fieldtype": "Column Break", + "fieldname": "col_break1", + "fieldtype": "Column Break", "permlevel": 0 - }, + }, { - "fieldname": "description", - "fieldtype": "Text", - "label": "Item Description", - "oldfieldname": "description", - "oldfieldtype": "Text", - "permlevel": 0, - "print_width": "250px", - "reqd": 0, - "width": "250px" - }, + "fieldname": "description", + "fieldtype": "Text", + "label": "Item Description", + "oldfieldname": "description", + "oldfieldtype": "Text", + "permlevel": 0, + "print_width": "250px", + "reqd": 0, + "width": "25px" + }, { - "fieldname": "quantity_and_rate", - "fieldtype": "Section Break", - "label": "Quantity and Rate", + "fieldname": "quantity_and_rate", + "fieldtype": "Section Break", + "label": "Quantity and Rate", "permlevel": 0 - }, + }, { - "fieldname": "qty", - "fieldtype": "Float", - "in_list_view": 1, - "label": "Qty", - "oldfieldname": "qty", - "oldfieldtype": "Currency", - "permlevel": 0, + "fieldname": "qty", + "fieldtype": "Float", + "in_list_view": 1, + "label": "Qty", + "oldfieldname": "qty", + "oldfieldtype": "Currency", + "permlevel": 0, "reqd": 1 - }, + }, { - "description": "See \"Rate Of Materials Based On\" in Costing Section", - "fieldname": "rate", - "fieldtype": "Currency", - "in_list_view": 1, - "label": "Rate", - "options": "Company:company:default_currency", - "permlevel": 0, + "description": "See \"Rate Of Materials Based On\" in Costing Section", + "fieldname": "rate", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Rate", + "options": "Company:company:default_currency", + "permlevel": 0, "reqd": 1 - }, + }, { - "fieldname": "col_break2", - "fieldtype": "Column Break", + "fieldname": "col_break2", + "fieldtype": "Column Break", "permlevel": 0 - }, + }, { - "fieldname": "stock_uom", - "fieldtype": "Link", - "in_list_view": 0, - "label": "Stock UOM", - "oldfieldname": "stock_uom", - "oldfieldtype": "Data", - "options": "UOM", - "permlevel": 0, - "read_only": 1, + "fieldname": "stock_uom", + "fieldtype": "Link", + "in_list_view": 0, + "label": "Stock UOM", + "oldfieldname": "stock_uom", + "oldfieldtype": "Data", + "options": "UOM", + "permlevel": 0, + "read_only": 1, "reqd": 1 - }, + }, { - "fieldname": "amount", - "fieldtype": "Currency", - "in_list_view": 1, - "label": "Amount", - "oldfieldname": "amount_as_per_mar", - "oldfieldtype": "Currency", - "options": "Company:company:default_currency", - "permlevel": 0, - "print_width": "150px", - "read_only": 1, + "fieldname": "amount", + "fieldtype": "Currency", + "in_list_view": 1, + "label": "Amount", + "oldfieldname": "amount_as_per_mar", + "oldfieldtype": "Currency", + "options": "Company:company:default_currency", + "permlevel": 0, + "print_width": "150px", + "read_only": 1, "width": "150px" - }, + }, { - "fieldname": "scrap", - "fieldtype": "Float", - "label": "Scrap %", - "oldfieldname": "scrap", - "oldfieldtype": "Currency", - "permlevel": 0, + "fieldname": "scrap", + "fieldtype": "Float", + "label": "Scrap %", + "oldfieldname": "scrap", + "oldfieldtype": "Currency", + "permlevel": 0, "print_hide": 1 - }, + }, { - "fieldname": "qty_consumed_per_unit", - "fieldtype": "Float", - "hidden": 1, - "label": "Qty Consumed Per Unit", - "oldfieldname": "qty_consumed_per_unit", - "oldfieldtype": "Float", - "permlevel": 0, - "print_hide": 1, + "fieldname": "qty_consumed_per_unit", + "fieldtype": "Float", + "hidden": 1, + "label": "Qty Consumed Per Unit", + "oldfieldname": "qty_consumed_per_unit", + "oldfieldtype": "Float", + "permlevel": 0, + "print_hide": 1, "read_only": 1 } - ], - "idx": 1, - "istable": 1, - "modified": "2014-12-12 11:15:43.798755", - "modified_by": "Administrator", - "module": "Manufacturing", - "name": "BOM Item", - "owner": "Administrator", - "permissions": [], - "sort_field": "modified", + ], + "idx": 1, + "istable": 1, + "modified": "2015-01-20 13:28:35.152945", + "modified_by": "Administrator", + "module": "Manufacturing", + "name": "BOM Item", + "owner": "Administrator", + "permissions": [], + "sort_field": "modified", "sort_order": "DESC" -} +} \ No newline at end of file diff --git a/erpnext/patches.txt b/erpnext/patches.txt index ccbf676229..9a74469f13 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -105,3 +105,4 @@ erpnext.patches.v5_0.recalculate_total_amount_in_jv erpnext.patches.v5_0.remove_shopping_cart_app erpnext.patches.v5_0.update_companywise_payment_account erpnext.patches.v5_0.remove_birthday_events +erpnext.patches.v5_0.update_item_name_in_bom diff --git a/erpnext/patches/v5_0/update_item_name_in_bom.py b/erpnext/patches/v5_0/update_item_name_in_bom.py new file mode 100644 index 0000000000..20c346ec23 --- /dev/null +++ b/erpnext/patches/v5_0/update_item_name_in_bom.py @@ -0,0 +1,12 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +import frappe + +def execute(): + frappe.db.sql("""update `tabBOM` set `tabBOM`.item_name = ( select `tabItem`.item_name \ + from `tabItem` where `tabItem`.name = `tabBOM`.item)""") + frappe.db.sql("""update `tabBOM Item` set item_name = ( select item_name \ + from tabItem where `tabItem`.name = `tabBOM Item`.item_code)""") + frappe.db.sql("""update `tabBOM Explosion Item` set `tabBOM Explosion Item`.item_name = \ + ( select `tabItem`.item_name from `tabItem` where `tabItem`.name = `tabBOM Explosion Item`.item_code)""") \ No newline at end of file From 7dac750ffed7c7b762cc88680ec0e3a3344a3c00 Mon Sep 17 00:00:00 2001 From: Neil Trini Lasrado Date: Tue, 20 Jan 2015 18:02:54 +0530 Subject: [PATCH 2/2] patch fix --- erpnext/patches/v5_0/update_item_name_in_bom.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/erpnext/patches/v5_0/update_item_name_in_bom.py b/erpnext/patches/v5_0/update_item_name_in_bom.py index 20c346ec23..1e858c5b22 100644 --- a/erpnext/patches/v5_0/update_item_name_in_bom.py +++ b/erpnext/patches/v5_0/update_item_name_in_bom.py @@ -4,9 +4,9 @@ import frappe def execute(): - frappe.db.sql("""update `tabBOM` set `tabBOM`.item_name = ( select `tabItem`.item_name \ - from `tabItem` where `tabItem`.name = `tabBOM`.item)""") - frappe.db.sql("""update `tabBOM Item` set item_name = ( select item_name \ - from tabItem where `tabItem`.name = `tabBOM Item`.item_code)""") - frappe.db.sql("""update `tabBOM Explosion Item` set `tabBOM Explosion Item`.item_name = \ - ( select `tabItem`.item_name from `tabItem` where `tabItem`.name = `tabBOM Explosion Item`.item_code)""") \ No newline at end of file + frappe.db.sql("""update `tabBOM` as bom set bom.item_name = \ + ( select item.item_name from `tabItem` as item where item.name = bom.item)""") + frappe.db.sql("""update `tabBOM Item` as bomItem set bomItem.item_name = ( select item.item_name \ + from `tabItem` as item where item.name = bomItem.item_code)""") + frappe.db.sql("""update `tabBOM Explosion Item` as explosionItem set explosionItem.item_name = \ + ( select item.item_name from `tabItem` as item where item.name = explosionItem.item_code)""") \ No newline at end of file