Allow user to change page_name in Item and Item Group #2397
This commit is contained in:
parent
28d21ba3c0
commit
d75ef108fc
@ -1,26 +1,12 @@
|
||||
// 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";
|
||||
|
||||
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")
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
frappe.ui.form.on("Item Group", {
|
||||
onload: function(frm) {
|
||||
frm.list_route = "Sales Browser/Item Group";
|
||||
|
||||
//get query select item group
|
||||
cur_frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) {
|
||||
frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) {
|
||||
return{
|
||||
filters:[
|
||||
['Item Group', 'is_group', '=', 'Yes'],
|
||||
@ -28,3 +14,23 @@ cur_frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) {
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
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");
|
||||
},
|
||||
|
||||
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
|
||||
});
|
||||
|
@ -3,55 +3,8 @@
|
||||
|
||||
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) {
|
||||
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({
|
||||
@ -84,30 +37,85 @@ frappe.ui.form.on("Item", "onload", function(frm) {
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
$.extend(erpnext.item, {
|
||||
setup_queries: function(frm) {
|
||||
// Expense Account
|
||||
// ---------------------------------
|
||||
cur_frm.fields_dict['expense_account'].get_query = function(doc) {
|
||||
frm.fields_dict['expense_account'].get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"report_type": "Profit and Loss",
|
||||
@ -118,7 +126,7 @@ cur_frm.fields_dict['expense_account'].get_query = function(doc) {
|
||||
|
||||
// Income Account
|
||||
// --------------------------------
|
||||
cur_frm.fields_dict['income_account'].get_query = function(doc) {
|
||||
frm.fields_dict['income_account'].get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"report_type": "Profit and Loss",
|
||||
@ -131,7 +139,7 @@ cur_frm.fields_dict['income_account'].get_query = function(doc) {
|
||||
|
||||
// Purchase Cost Center
|
||||
// -----------------------------
|
||||
cur_frm.fields_dict['buying_cost_center'].get_query = function(doc) {
|
||||
frm.fields_dict['buying_cost_center'].get_query = function(doc) {
|
||||
return {
|
||||
filters:{ 'group_or_ledger': "Ledger" }
|
||||
}
|
||||
@ -140,14 +148,14 @@ cur_frm.fields_dict['buying_cost_center'].get_query = function(doc) {
|
||||
|
||||
// Sales Cost Center
|
||||
// -----------------------------
|
||||
cur_frm.fields_dict['selling_cost_center'].get_query = function(doc) {
|
||||
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) {
|
||||
frm.fields_dict['taxes'].grid.get_field("tax_type").get_query = function(doc, cdt, cdn) {
|
||||
return {
|
||||
filters: [
|
||||
['Account', 'account_type', 'in',
|
||||
@ -157,12 +165,7 @@ cur_frm.fields_dict['taxes'].grid.get_field("tax_type").get_query = function(doc
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
cur_frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) {
|
||||
frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) {
|
||||
return {
|
||||
filters: [
|
||||
['Item Group', 'docstatus', '!=', 2]
|
||||
@ -170,33 +173,37 @@ cur_frm.fields_dict['item_group'].get_query = function(doc,cdt,cdn) {
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
frm.fields_dict.customer_items.grid.get_field("customer_name").get_query = function(doc, cdt, cdn) {
|
||||
return { query: "erpnext.controllers.queries.customer_query" }
|
||||
}
|
||||
|
||||
cur_frm.fields_dict.supplier_items.grid.get_field("supplier").get_query = function(doc, cdt, cdn) {
|
||||
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.copy_from_item_group = function(doc) {
|
||||
return cur_frm.call({
|
||||
doc: doc,
|
||||
method: "copy_specification_from_item_group"
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
cur_frm.cscript.image = function() {
|
||||
refresh_field("image_view");
|
||||
toggle_reqd: function(frm) {
|
||||
frm.toggle_reqd("default_warehouse", frm.doc.is_stock_item==="Yes");
|
||||
},
|
||||
|
||||
make_dashboard: function(frm) {
|
||||
frm.dashboard.reset();
|
||||
if(frm.doc.__islocal)
|
||||
return;
|
||||
},
|
||||
|
||||
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");
|
||||
},
|
||||
|
||||
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;
|
||||
}
|
||||
},
|
||||
|
||||
});
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user