From d75ef108fcbe372ecde6e539c6e815d24f40be28 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Wed, 25 Feb 2015 13:50:14 +0530 Subject: [PATCH] Allow user to change page_name in Item and Item Group #2397 --- .../setup/doctype/item_group/item_group.js | 54 +-- erpnext/stock/doctype/item/item.js | 357 +++++++++--------- erpnext/stock/doctype/item/item.json | 4 +- 3 files changed, 214 insertions(+), 201 deletions(-) diff --git a/erpnext/setup/doctype/item_group/item_group.js b/erpnext/setup/doctype/item_group/item_group.js index 717c7d61e4..67e4e99bc0 100644 --- a/erpnext/setup/doctype/item_group/item_group.js +++ b/erpnext/setup/doctype/item_group/item_group.js @@ -1,30 +1,36 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt -cur_frm.list_route = "Sales Browser/Item Group"; +frappe.ui.form.on("Item Group", { + onload: function(frm) { + frm.list_route = "Sales Browser/Item Group"; -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - cur_frm.cscript.set_root_readonly(doc); - cur_frm.add_custom_button(__("Item Group Tree"), function() { - frappe.set_route("Sales Browser", "Item Group"); - }, "icon-sitemap") -} + //get query select item group + frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) { + return{ + filters:[ + ['Item Group', 'is_group', '=', 'Yes'], + ['Item Group', 'name', '!=', doc.item_group_name] + ] + } + } + }, -cur_frm.cscript.set_root_readonly = function(doc) { - // read-only for root item group - cur_frm.set_intro(""); - if(!doc.parent_item_group) { - cur_frm.set_read_only(); - cur_frm.set_intro(__("This is a root item group and cannot be edited."), true); - } -} + refresh: function(frm) { + frm.trigger("set_root_readonly"); + frm.add_custom_button(__("Item Group Tree"), function() { + frappe.set_route("Sales Browser", "Item Group"); + }, "icon-sitemap"); + }, -//get query select item group -cur_frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) { - return{ - filters:[ - ['Item Group', 'is_group', '=', 'Yes'], - ['Item Group', 'name', '!=', doc.item_group_name] - ] - } -} + set_root_readonly: function(frm) { + // read-only for root item group + frm.set_intro(""); + if(!frm.doc.parent_item_group) { + frm.set_read_only(); + frm.set_intro(__("This is a root item group and cannot be edited."), true); + } + }, + + page_name: frappe.utils.warn_page_name_change +}); diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js index 33b1720f06..df1589172a 100644 --- a/erpnext/stock/doctype/item/item.js +++ b/erpnext/stock/doctype/item/item.js @@ -3,200 +3,207 @@ frappe.provide("erpnext.item"); -frappe.ui.form.on("Item", "refresh", function(frm) { - if(frm.doc.is_stock_item) { - frm.add_custom_button(__("Show Balance"), function() { - frappe.route_options = { - "item_code": frm.doc.name - } - frappe.set_route("query-report", "Stock Balance"); - }); - } -}) - -cur_frm.cscript.refresh = function(doc) { - // make sensitive fields(has_serial_no, is_stock_item, valuation_method) - // read only if any stock ledger entry exists - - cur_frm.cscript.make_dashboard(); - - if (cur_frm.doc.has_variants) { - cur_frm.set_intro(__("This Item is a Template and cannot be used in transactions. Item attributes will be copied over into the variants unless 'No Copy' is set"), true); - cur_frm.add_custom_button(__("Show Variants"), function() { - frappe.set_route("List", "Item", {"variant_of": cur_frm.doc.name}); - }, "icon-list", "btn-default"); - } - if (cur_frm.doc.variant_of) { - cur_frm.set_intro(__("This Item is a Variant of {0} (Template). Attributes will be copied over from the template unless 'No Copy' is set", [cur_frm.doc.variant_of]), true); - } - - if (frappe.defaults.get_default("item_naming_by")!="Naming Series") { - cur_frm.toggle_display("naming_series", false); - } else { - erpnext.toggle_naming_series(); - } - - - cur_frm.cscript.edit_prices_button(); - - if (!doc.__islocal && doc.is_stock_item == 'Yes') { - cur_frm.toggle_enable(['has_serial_no', 'is_stock_item', 'valuation_method', 'has_batch_no'], - (doc.__onload && doc.__onload.sle_exists=="exists") ? false : true); - } - - erpnext.item.toggle_reqd(cur_frm); -} - -erpnext.item.toggle_reqd = function(frm) { - frm.toggle_reqd("default_warehouse", frm.doc.is_stock_item==="Yes"); -}; - -frappe.ui.form.on("Item", "onload", function(frm) { - var df = frappe.meta.get_docfield("Item Variant", "item_attribute_value"); - df.on_make = function(field) { - field.$input.autocomplete({ - minLength: 0, - minChars: 0, - source: function(request, response) { - frappe.call({ - method:"frappe.client.get_list", - args:{ - doctype:"Item Attribute Value", - filters: [ - ["parent","=", field.doc.item_attribute], - ["attribute_value", "like", request.term + "%"] - ], - fields: ["attribute_value"] - }, - callback: function(r) { - response($.map(r.message, function(d) { return d.attribute_value; })); +frappe.ui.form.on("Item", { + onload: function(frm) { + var df = frappe.meta.get_docfield("Item Variant", "item_attribute_value"); + df.on_make = function(field) { + field.$input.autocomplete({ + minLength: 0, + minChars: 0, + source: function(request, response) { + frappe.call({ + method:"frappe.client.get_list", + args:{ + doctype:"Item Attribute Value", + filters: [ + ["parent","=", field.doc.item_attribute], + ["attribute_value", "like", request.term + "%"] + ], + fields: ["attribute_value"] + }, + callback: function(r) { + response($.map(r.message, function(d) { return d.attribute_value; })); + } + }); + }, + select: function(event, ui) { + field.$input.val(ui.item.value); + field.$input.trigger("change"); + }, + focus: function( event, ui ) { + if(ui.item.action) { + return false; } - }); - }, - select: function(event, ui) { - field.$input.val(ui.item.value); - field.$input.trigger("change"); - }, - focus: function( event, ui ) { - if(ui.item.action) { - return false; + }, + }); + } + + erpnext.item.setup_queries(frm); + }, + + refresh: function(frm) { + if(frm.doc.is_stock_item) { + frm.add_custom_button(__("Show Balance"), function() { + frappe.route_options = { + "item_code": frm.doc.name } - }, + frappe.set_route("query-report", "Stock Balance"); + }); + } + + // make sensitive fields(has_serial_no, is_stock_item, valuation_method) + // read only if any stock ledger entry exists + erpnext.item.make_dashboard(frm); + + if (frm.doc.has_variants) { + frm.set_intro(__("This Item is a Template and cannot be used in transactions. Item attributes will be copied over into the variants unless 'No Copy' is set"), true); + frm.add_custom_button(__("Show Variants"), function() { + frappe.set_route("List", "Item", {"variant_of": frm.doc.name}); + }, "icon-list", "btn-default"); + } + if (frm.doc.variant_of) { + frm.set_intro(__("This Item is a Variant of {0} (Template). Attributes will be copied over from the template unless 'No Copy' is set", [frm.doc.variant_of]), true); + } + + if (frappe.defaults.get_default("item_naming_by")!="Naming Series") { + frm.toggle_display("naming_series", false); + } else { + erpnext.toggle_naming_series(); + } + + erpnext.item.edit_prices_button(frm); + + if (!frm.doc.__islocal && frm.doc.is_stock_item == 'Yes') { + frm.toggle_enable(['has_serial_no', 'is_stock_item', 'valuation_method', 'has_batch_no'], + (frm.doc.__onload && frm.doc.__onload.sle_exists=="exists") ? false : true); + } + + erpnext.item.toggle_reqd(frm); + }, + + validate: function(frm){ + erpnext.item.weight_to_validate(frm); + }, + + image: function(frm) { + refresh_field("image_view"); + }, + + page_name: frappe.utils.warn_page_name_change + + item_code: function(frm) { + if(!frm.doc.item_name) + frm.set_value("item_name", frm.doc.item_code); + if(!frm.doc.description) + frm.set_value("description", frm.doc.item_code); + }, + + tax_type: function(frm, cdt, cdn){ + var d = locals[cdt][cdn]; + return get_server_fields('get_tax_rate', d.tax_type, 'taxes', doc, cdt, cdn, 1); + }, + + copy_from_item_group: function(frm) { + return frm.call({ + doc: frm.doc, + method: "copy_specification_from_item_group" }); - } + }, }); -cur_frm.cscript.make_dashboard = function() { - cur_frm.dashboard.reset(); - if(cur_frm.doc.__islocal) - return; -} - -cur_frm.cscript.edit_prices_button = function() { - cur_frm.add_custom_button(__("Add / Edit Prices"), function() { - frappe.set_route("Report", "Item Price", {"item_code": cur_frm.doc.name}); - }, "icon-money", "btn-default"); -} - -cur_frm.cscript.item_code = function(doc) { - if(!doc.item_name) - cur_frm.set_value("item_name", doc.item_code); - if(!doc.description) - cur_frm.set_value("description", doc.item_code); -} - -// Expense Account -// --------------------------------- -cur_frm.fields_dict['expense_account'].get_query = function(doc) { - return { - filters: { - "report_type": "Profit and Loss", - "group_or_ledger": "Ledger" +$.extend(erpnext.item, { + setup_queries: function(frm) { + // Expense Account + // --------------------------------- + frm.fields_dict['expense_account'].get_query = function(doc) { + return { + filters: { + "report_type": "Profit and Loss", + "group_or_ledger": "Ledger" + } + } } - } -} -// Income Account -// -------------------------------- -cur_frm.fields_dict['income_account'].get_query = function(doc) { - return { - filters: { - "report_type": "Profit and Loss", - 'group_or_ledger': "Ledger", - 'account_type': "Income Account" + // Income Account + // -------------------------------- + frm.fields_dict['income_account'].get_query = function(doc) { + return { + filters: { + "report_type": "Profit and Loss", + 'group_or_ledger': "Ledger", + 'account_type': "Income Account" + } + } } - } -} -// Purchase Cost Center -// ----------------------------- -cur_frm.fields_dict['buying_cost_center'].get_query = function(doc) { - return { - filters:{ 'group_or_ledger': "Ledger" } - } -} + // Purchase Cost Center + // ----------------------------- + frm.fields_dict['buying_cost_center'].get_query = function(doc) { + return { + filters:{ 'group_or_ledger': "Ledger" } + } + } -// Sales Cost Center -// ----------------------------- -cur_frm.fields_dict['selling_cost_center'].get_query = function(doc) { - return { - filters:{ 'group_or_ledger': "Ledger" } - } -} + // Sales Cost Center + // ----------------------------- + frm.fields_dict['selling_cost_center'].get_query = function(doc) { + return { + filters:{ 'group_or_ledger': "Ledger" } + } + } -cur_frm.fields_dict['taxes'].grid.get_field("tax_type").get_query = function(doc, cdt, cdn) { - return { - filters: [ - ['Account', 'account_type', 'in', - 'Tax, Chargeable, Income Account, Expense Account'], - ['Account', 'docstatus', '!=', 2] - ] - } -} + frm.fields_dict['taxes'].grid.get_field("tax_type").get_query = function(doc, cdt, cdn) { + return { + filters: [ + ['Account', 'account_type', 'in', + 'Tax, Chargeable, Income Account, Expense Account'], + ['Account', 'docstatus', '!=', 2] + ] + } + } -cur_frm.cscript.tax_type = function(doc, cdt, cdn){ - var d = locals[cdt][cdn]; - return get_server_fields('get_tax_rate', d.tax_type, 'taxes', doc, cdt, cdn, 1); -} + frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) { + return { + filters: [ + ['Item Group', 'docstatus', '!=', 2] + ] + } + } -cur_frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) { - return { - filters: [ - ['Item Group', 'docstatus', '!=', 2] - ] - } -} + frm.fields_dict.customer_items.grid.get_field("customer_name").get_query = function(doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.customer_query" } + } -// Quotation to validation - either customer or lead mandatory -cur_frm.cscript.weight_to_validate = function(doc, cdt, cdn){ - if((doc.nett_weight || doc.gross_weight) && !doc.weight_uom) { - msgprint(__('Weight is mentioned,\nPlease mention "Weight UOM" too')); - validated = 0; - } -} + frm.fields_dict.supplier_items.grid.get_field("supplier").get_query = function(doc, cdt, cdn) { + return { query: "erpnext.controllers.queries.supplier_query" } + } -cur_frm.cscript.validate = function(doc, cdt, cdn){ - cur_frm.cscript.weight_to_validate(doc, cdt, cdn); -} + }, -cur_frm.fields_dict.customer_items.grid.get_field("customer_name").get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.customer_query" } -} + toggle_reqd: function(frm) { + frm.toggle_reqd("default_warehouse", frm.doc.is_stock_item==="Yes"); + }, -cur_frm.fields_dict.supplier_items.grid.get_field("supplier").get_query = function(doc, cdt, cdn) { - return { query: "erpnext.controllers.queries.supplier_query" } -} + make_dashboard: function(frm) { + frm.dashboard.reset(); + if(frm.doc.__islocal) + return; + }, -cur_frm.cscript.copy_from_item_group = function(doc) { - return cur_frm.call({ - doc: doc, - method: "copy_specification_from_item_group" - }); -} + edit_prices_button: function(frm) { + frm.add_custom_button(__("Add / Edit Prices"), function() { + frappe.set_route("Report", "Item Price", {"item_code": frm.doc.name}); + }, "icon-money", "btn-default"); + }, -cur_frm.cscript.image = function() { - refresh_field("image_view"); -} + weight_to_validate: function(frm){ + if((frm.doc.nett_weight || frm.doc.gross_weight) && !frm.doc.weight_uom) { + msgprint(__('Weight is mentioned,\nPlease mention "Weight UOM" too')); + validated = 0; + } + }, + +}); diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json index 70826fb62b..28bfb5a184 100644 --- a/erpnext/stock/doctype/item/item.json +++ b/erpnext/stock/doctype/item/item.json @@ -772,7 +772,7 @@ "label": "Page Name", "no_copy": 1, "permlevel": 0, - "read_only": 1 + "read_only": 0 }, { "depends_on": "show_in_website", @@ -876,7 +876,7 @@ "icon": "icon-tag", "idx": 1, "max_attachments": 1, - "modified": "2015-02-24 05:19:07.382483", + "modified": "2015-02-25 02:46:14.483577", "modified_by": "Administrator", "module": "Stock", "name": "Item",