From 3e41fd1fd338503c600f266a23a21ef9424a7633 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 22 Apr 2014 18:54:54 +0530 Subject: [PATCH] List route for tree browser based doctypes; Fixes to add child in tree browsers --- erpnext/accounts/doctype/account/account.js | 42 ++++++------ .../doctype/cost_center/cost_center.js | 19 +++--- .../doctype/sales_invoice/sales_invoice.py | 3 +- .../page/accounts_browser/accounts_browser.js | 66 +++++++++---------- erpnext/accounts/utils.py | 9 +-- .../doctype/purchase_order/purchase_order.py | 8 +-- .../supplier_quotation/supplier_quotation.py | 37 +++++------ .../salary_structure/salary_structure.py | 7 +- .../doctype/sales_order/sales_order.py | 8 +-- .../page/sales_browser/sales_browser.js | 54 +++++++-------- .../page/sales_browser/sales_browser.py | 23 ++++--- .../doctype/customer_group/customer_group.js | 8 ++- .../setup/doctype/item_group/item_group.js | 3 +- .../doctype/sales_person/sales_person.js | 4 +- erpnext/setup/doctype/territory/territory.js | 4 +- 15 files changed, 150 insertions(+), 145 deletions(-) diff --git a/erpnext/accounts/doctype/account/account.js b/erpnext/accounts/doctype/account/account.js index 2a805cfca3..4b865ed363 100644 --- a/erpnext/accounts/doctype/account/account.js +++ b/erpnext/accounts/doctype/account/account.js @@ -1,6 +1,8 @@ // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt +cur_frm.list_route = "Accounts Browser/Account"; + cur_frm.cscript.refresh = function(doc, cdt, cdn) { if(doc.__islocal) { msgprint(__("Please create new account from Chart of Accounts.")); @@ -8,20 +10,20 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { } cur_frm.toggle_display('account_name', doc.__islocal); - + // hide fields if group - cur_frm.toggle_display(['account_type', 'master_type', 'master_name', - 'credit_days', 'credit_limit', 'tax_rate'], doc.group_or_ledger=='Ledger') - + cur_frm.toggle_display(['account_type', 'master_type', 'master_name', + 'credit_days', 'credit_limit', 'tax_rate'], doc.group_or_ledger=='Ledger') + // disable fields cur_frm.toggle_enable(['account_name', 'group_or_ledger', 'company'], false); - + if(doc.group_or_ledger=='Ledger') { frappe.model.with_doc("Accounts Settings", "Accounts Settings", function (name) { var accounts_settings = frappe.get_doc("Accounts Settings", name); - var display = accounts_settings["frozen_accounts_modifier"] + var display = accounts_settings["frozen_accounts_modifier"] && in_list(user_roles, accounts_settings["frozen_accounts_modifier"]); - + cur_frm.toggle_display('freeze_account', display); }); } @@ -33,9 +35,9 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { } else { // credit days and type if customer or supplier cur_frm.set_intro(null); - cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'], + cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'], doc.master_type)); - + cur_frm.cscript.master_type(doc, cdt, cdn); cur_frm.cscript.account_type(doc, cdt, cdn); @@ -45,10 +47,10 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { } cur_frm.cscript.master_type = function(doc, cdt, cdn) { - cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'], + cur_frm.toggle_display(['credit_days', 'credit_limit'], in_list(['Customer', 'Supplier'], doc.master_type)); - - cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' || + + cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' || in_list(['Customer', 'Supplier'], doc.master_type)); } @@ -58,22 +60,22 @@ cur_frm.cscript.account_type = function(doc, cdt, cdn) { if(doc.group_or_ledger=='Ledger') { cur_frm.toggle_display(['tax_rate'], doc.account_type == 'Tax'); cur_frm.toggle_display('master_type', cstr(doc.account_type)==''); - cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' || + cur_frm.toggle_display('master_name', doc.account_type=='Warehouse' || in_list(['Customer', 'Supplier'], doc.master_type)); } } cur_frm.cscript.add_toolbar_buttons = function(doc) { - cur_frm.appframe.add_button(__('Chart of Accounts'), + cur_frm.appframe.add_button(__('Chart of Accounts'), function() { frappe.set_route("Accounts Browser", "Account"); }, 'icon-sitemap') if (cstr(doc.group_or_ledger) == 'Group') { - cur_frm.add_custom_button(__('Convert to Ledger'), + cur_frm.add_custom_button(__('Convert to Ledger'), function() { cur_frm.cscript.convert_to_ledger(); }, 'icon-retweet') } else if (cstr(doc.group_or_ledger) == 'Ledger') { - cur_frm.add_custom_button(__('Convert to Group'), + cur_frm.add_custom_button(__('Convert to Group'), function() { cur_frm.cscript.convert_to_group(); }, 'icon-retweet') - + cur_frm.appframe.add_button(__('View Ledger'), function() { frappe.route_options = { "account": doc.name, @@ -88,7 +90,7 @@ cur_frm.cscript.add_toolbar_buttons = function(doc) { cur_frm.cscript.convert_to_ledger = function(doc, cdt, cdn) { return $c_obj(cur_frm.doc,'convert_group_to_ledger','',function(r,rt) { - if(r.message == 1) { + if(r.message == 1) { cur_frm.refresh(); } }); @@ -119,8 +121,8 @@ cur_frm.fields_dict['master_name'].get_query = function(doc) { cur_frm.fields_dict['parent_account'].get_query = function(doc) { return { filters: { - "group_or_ledger": "Group", + "group_or_ledger": "Group", "company": doc.company } } -} \ No newline at end of file +} diff --git a/erpnext/accounts/doctype/cost_center/cost_center.js b/erpnext/accounts/doctype/cost_center/cost_center.js index 71239bafc1..808ad52889 100644 --- a/erpnext/accounts/doctype/cost_center/cost_center.js +++ b/erpnext/accounts/doctype/cost_center/cost_center.js @@ -2,11 +2,14 @@ // License: GNU General Public License v3. See license.txt frappe.provide("erpnext.accounts"); + +cur_frm.list_route = "Accounts Browser/Cost Center"; + erpnext.accounts.CostCenterController = frappe.ui.form.Controller.extend({ onload: function() { this.setup_queries(); }, - + setup_queries: function() { var me = this; if(this.frm.fields_dict["budget_details"].grid.get_field("account")) { @@ -20,10 +23,10 @@ erpnext.accounts.CostCenterController = frappe.ui.form.Controller.extend({ } }); } - + this.frm.set_query("parent_cost_center", function() { return { - filters:[ + filters:[ ['Cost Center', 'group_or_ledger', '=', 'Group'], ['Cost Center', 'company', '=', me.frm.doc.company], ] @@ -44,11 +47,11 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { } cur_frm.cscript.hide_unhide_group_ledger(doc); - + cur_frm.toggle_display('sb1', doc.group_or_ledger=='Ledger') cur_frm.set_intro(intro_txt); - - cur_frm.appframe.add_button(__('Chart of Cost Centers'), + + cur_frm.appframe.add_button(__('Chart of Cost Centers'), function() { frappe.set_route("Accounts Browser", "Cost Center"); }, 'icon-sitemap') } @@ -60,10 +63,10 @@ cur_frm.cscript.parent_cost_center = function(doc, cdt, cdn) { cur_frm.cscript.hide_unhide_group_ledger = function(doc) { if (cstr(doc.group_or_ledger) == 'Group') { - cur_frm.add_custom_button(__('Convert to Ledger'), + cur_frm.add_custom_button(__('Convert to Ledger'), function() { cur_frm.cscript.convert_to_ledger(); }, 'icon-retweet') } else if (cstr(doc.group_or_ledger) == 'Ledger') { - cur_frm.add_custom_button(__('Convert to Group'), + cur_frm.add_custom_button(__('Convert to Group'), function() { cur_frm.cscript.convert_to_group(); }, 'icon-retweet') } } diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py index b40722c116..6d4bf3a6df 100644 --- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py +++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py @@ -784,8 +784,7 @@ def make_delivery_note(source_name, target_doc=None): from frappe.model.mapper import get_mapped_doc def set_missing_values(source, target): - doc = frappe.get_doc(target) - doc.run_method("onload_post_render") + target.run_method("onload_post_render") def update_item(source_doc, target_doc, source_parent): target_doc.base_amount = (flt(source_doc.qty) - flt(source_doc.delivered_qty)) * \ diff --git a/erpnext/accounts/page/accounts_browser/accounts_browser.js b/erpnext/accounts/page/accounts_browser/accounts_browser.js index a94a923166..ca6ebffdd1 100644 --- a/erpnext/accounts/page/accounts_browser/accounts_browser.js +++ b/erpnext/accounts/page/accounts_browser/accounts_browser.js @@ -12,7 +12,7 @@ pscript['onload_Accounts Browser'] = function(wrapper){ parent: wrapper, single_column: true }) - + wrapper.appframe.add_module_icon("Accounts"); var main = $(wrapper).find(".layout-main"), @@ -30,7 +30,7 @@ pscript['onload_Accounts Browser'] = function(wrapper){ ''+ '
  • '+__('Please do NOT create Account (Ledgers) for Customers and Suppliers. They are created directly from the Customer / Supplier masters.')+'
  • '+ '
  • '+ - ''+__('To create a Bank Account:')+''+ + ''+__('To create a Bank Account:')+''+ __('Go to the appropriate group (usually Application of Funds > Current Assets > Bank Accounts and create a new Account Ledger (by clicking on Add Child) of type "Bank"')+ '
  • '+ '
  • '+ @@ -39,13 +39,13 @@ pscript['onload_Accounts Browser'] = function(wrapper){ '
  • '+ ''+ '

    '+__('Please setup your chart of accounts before you start Accounting Entries')+'

    ').appendTo(main); - + if (frappe.boot.user.can_create.indexOf("Company") !== -1) { wrapper.appframe.add_button(__('New Company'), function() { newdoc('Company'); }, 'icon-plus'); } - - wrapper.appframe.set_title_right('Refresh', function() { + + wrapper.appframe.set_title_right('Refresh', function() { wrapper.$company_select.change(); }); @@ -53,11 +53,11 @@ pscript['onload_Accounts Browser'] = function(wrapper){ wrapper.$company_select = wrapper.appframe.add_select("Company", []) .change(function() { var ctype = frappe.get_route()[1] || 'Account'; - erpnext.account_chart = new erpnext.AccountsChart(ctype, $(this).val(), + erpnext.account_chart = new erpnext.AccountsChart(ctype, $(this).val(), chart_area.get(0)); pscript.set_title(wrapper, ctype, $(this).val()); }) - + // load up companies return frappe.call({ method: 'erpnext.accounts.page.accounts_browser.accounts_browser.get_companies', @@ -86,7 +86,7 @@ pscript['onshow_Accounts Browser'] = function(wrapper){ if(erpnext.account_chart && erpnext.account_chart.ctype != ctype) { wrapper.$company_select.change(); } - + pscript.set_title(wrapper, ctype); } @@ -98,11 +98,11 @@ erpnext.AccountsChart = Class.extend({ me.can_create = frappe.model.can_create(this.ctype); me.can_delete = frappe.model.can_delete(this.ctype); me.can_write = frappe.model.can_write(this.ctype); - - + + me.company = company; this.tree = new frappe.ui.Tree({ - parent: $(wrapper), + parent: $(wrapper), label: ctype==="Account" ? "Accounts" : "Cost Centers", args: {ctype: ctype, comp: company}, method: 'erpnext.accounts.page.accounts_browser.accounts_browser.get_children', @@ -114,7 +114,7 @@ erpnext.AccountsChart = Class.extend({ }, toolbar: [ { toggle_btn: true }, - { + { label: __("Open"), condition: function(node) { return !node.root }, click: function(node, btn) { @@ -134,7 +134,7 @@ erpnext.AccountsChart = Class.extend({ }, { condition: function(node) { - return !node.root && me.ctype === 'Account' + return !node.root && me.ctype === 'Account' && frappe.boot.user.can_read.indexOf("GL Entry") !== -1 }, label: __("View Ledger"), @@ -147,7 +147,7 @@ erpnext.AccountsChart = Class.extend({ }; frappe.set_route("query-report", "General Ledger"); } - + }, { condition: function(node) { return !node.root && me.can_write }, @@ -170,8 +170,8 @@ erpnext.AccountsChart = Class.extend({ ], onrender: function(node) { if (me.ctype == 'Account' && node.data && node.data.balance!==undefined) { - $('' - + format_currency(node.data.balance, node.data.currency) + $('' + + format_currency(node.data.balance, node.data.currency) + '').insertBefore(node.$ul); } } @@ -179,18 +179,18 @@ erpnext.AccountsChart = Class.extend({ }, new_account: function() { var me = this; - + // the dialog var d = new frappe.ui.Dialog({ title:__('New Account'), fields: [ - {fieldtype:'Data', fieldname:'account_name', label:__('New Account Name'), reqd:true, + {fieldtype:'Data', fieldname:'account_name', label:__('New Account Name'), reqd:true, description: __("Name of new Account. Note: Please don't create accounts for Customers and Suppliers, they are created automatically from the Customer and Supplier master")}, {fieldtype:'Select', fieldname:'group_or_ledger', label:__('Group or Ledger'), options:'Group\nLedger', description: __('Further accounts can be made under Groups, but entries can be made against Ledger')}, {fieldtype:'Select', fieldname:'account_type', label:__('Account Type'), - options: ['', 'Bank', 'Cash', 'Warehouse', 'Receivable', 'Payable', - 'Equity', 'Cost of Goods Sold', 'Fixed Asset', 'Expense Account', + options: ['', 'Bank', 'Cash', 'Warehouse', 'Receivable', 'Payable', + 'Equity', 'Cost of Goods Sold', 'Fixed Asset', 'Expense Account', 'Income Account', 'Tax', 'Chargeable'].join('\n'), description: __("Optional. This setting will be used to filter in various transactions.") }, {fieldtype:'Float', fieldname:'tax_rate', label:__('Tax Rate')}, @@ -199,7 +199,7 @@ erpnext.AccountsChart = Class.extend({ }) var fd = d.fields_dict; - + // account type if ledger $(fd.group_or_ledger.input).change(function() { if($(this).val()=='Group') { @@ -212,7 +212,7 @@ erpnext.AccountsChart = Class.extend({ } } }); - + // tax rate if tax $(fd.account_type.input).change(function() { if($(this).val()=='Tax') { @@ -221,38 +221,38 @@ erpnext.AccountsChart = Class.extend({ $(fd.tax_rate.wrapper).toggle(false); } }) - + // create $(fd.create_new.input).click(function() { var btn = this; var v = d.get_values(); if(!v) return; - + var node = me.tree.get_selected_node(); v.parent_account = node.label; v.master_type = ''; v.company = me.company; - + return frappe.call({ args: v, method: 'erpnext.accounts.utils.add_ac', callback: function(r) { d.hide(); - node.reload; + node.reload(); } }); }); - + // show d.onshow = function() { $(fd.group_or_ledger.input).change(); $(fd.account_type.input).change(); } - + $(fd.group_or_ledger.input).val("Ledger").change(); d.show(); }, - + new_cost_center: function(){ var me = this; // the dialog @@ -265,17 +265,17 @@ erpnext.AccountsChart = Class.extend({ {fieldtype:'Button', fieldname:'create_new', label:__('Create New') } ] }); - + // create $(d.fields_dict.create_new.input).click(function() { var v = d.get_values(); if(!v) return; - + var node = me.tree.get_selected_node(); - + v.parent_cost_center = node.label; v.company = me.company; - + return frappe.call({ args: v, method: 'erpnext.accounts.utils.add_cc', diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py index 4eb5045038..e215ae6f92 100644 --- a/erpnext/accounts/utils.py +++ b/erpnext/accounts/utils.py @@ -99,11 +99,12 @@ def add_ac(args=None): args = frappe.local.form_dict args.pop("cmd") - ac = frappe.get_doc(args) - ac.doctype = "Account" + ac = frappe.new_doc("Account") + ac.update(args) ac.old_parent = "" ac.freeze_account = "No" ac.insert() + return ac.name @frappe.whitelist() @@ -112,8 +113,8 @@ def add_cc(args=None): args = frappe.local.form_dict args.pop("cmd") - cc = frappe.get_doc(args) - cc.doctype = "Cost Center" + cc = frappe.new_doc("Cost Center") + cc.update(args) cc.old_parent = "" cc.insert() return cc.name diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py index a83debcce7..c33039fad1 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.py +++ b/erpnext/buying/doctype/purchase_order/purchase_order.py @@ -4,7 +4,7 @@ from __future__ import unicode_literals import frappe from frappe.utils import cstr, flt -from frappe import msgprint, _ +from frappe import msgprint, _, throw from erpnext.controllers.buying_controller import BuyingController class PurchaseOrder(BuyingController): @@ -183,8 +183,7 @@ def make_purchase_receipt(source_name, target_doc=None): from frappe.model.mapper import get_mapped_doc def set_missing_values(source, target): - doc = frappe.get_doc(target) - doc.run_method("set_missing_values") + target.run_method("set_missing_values") def update_item(obj, target, source_parent): target.qty = flt(obj.qty) - flt(obj.received_qty) @@ -222,8 +221,7 @@ def make_purchase_invoice(source_name, target_doc=None): from frappe.model.mapper import get_mapped_doc def set_missing_values(source, target): - doc = frappe.get_doc(target) - doc.run_method("set_missing_values") + target.run_method("set_missing_values") def update_item(obj, target, source_parent): target.amount = flt(obj.amount) - flt(obj.billed_amt) diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py index fa48488766..84eeccf4fa 100644 --- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py +++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.py @@ -8,17 +8,17 @@ from erpnext.controllers.buying_controller import BuyingController class SupplierQuotation(BuyingController): tname = "Supplier Quotation Item" fname = "quotation_items" - + def validate(self): super(SupplierQuotation, self).validate() - + if not self.status: self.status = "Draft" from erpnext.utilities import validate_status - validate_status(self.status, ["Draft", "Submitted", "Stopped", + validate_status(self.status, ["Draft", "Submitted", "Stopped", "Cancelled"]) - + self.validate_common() self.validate_with_previous_doc() self.validate_uom_is_integer("uom", "qty") @@ -28,10 +28,10 @@ class SupplierQuotation(BuyingController): def on_cancel(self): frappe.db.set(self, "status", "Cancelled") - + def on_trash(self): pass - + def validate_with_previous_doc(self): super(SupplierQuotation, self).validate_with_previous_doc(self.tname, { "Material Request": { @@ -45,7 +45,7 @@ class SupplierQuotation(BuyingController): } }) - + def validate_common(self): pc = frappe.get_doc('Purchase Common') pc.validate_for_items(self) @@ -53,27 +53,26 @@ class SupplierQuotation(BuyingController): @frappe.whitelist() def make_purchase_order(source_name, target_doc=None): from frappe.model.mapper import get_mapped_doc - + def set_missing_values(source, target): - doc = frappe.get_doc(target) - doc.run_method("set_missing_values") - doc.run_method("get_schedule_dates") + target.run_method("set_missing_values") + target.run_method("get_schedule_dates") def update_item(obj, target, source_parent): target.conversion_factor = 1 doclist = get_mapped_doc("Supplier Quotation", source_name, { "Supplier Quotation": { - "doctype": "Purchase Order", + "doctype": "Purchase Order", "validation": { "docstatus": ["=", 1], } - }, + }, "Supplier Quotation Item": { - "doctype": "Purchase Order Item", + "doctype": "Purchase Order Item", "field_map": [ - ["name", "supplier_quotation_item"], - ["parent", "supplier_quotation"], + ["name", "supplier_quotation_item"], + ["parent", "supplier_quotation"], ["uom", "stock_uom"], ["uom", "uom"], ["prevdoc_detail_docname", "prevdoc_detail_docname"], @@ -81,11 +80,11 @@ def make_purchase_order(source_name, target_doc=None): ["prevdoc_docname", "prevdoc_docname"] ], "postprocess": update_item - }, + }, "Purchase Taxes and Charges": { - "doctype": "Purchase Taxes and Charges", + "doctype": "Purchase Taxes and Charges", "add_if_empty": True }, }, target_doc, set_missing_values) - return doclist \ No newline at end of file + return doclist diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.py b/erpnext/hr/doctype/salary_structure/salary_structure.py index 6843644d40..a57a0ce046 100644 --- a/erpnext/hr/doctype/salary_structure/salary_structure.py +++ b/erpnext/hr/doctype/salary_structure/salary_structure.py @@ -76,10 +76,9 @@ def get_mapped_doc(source_name, target_doc=None): from frappe.model.mapper import get_mapped_doc def postprocess(source, target): - sal_slip = frappe.get_doc(target) - sal_slip.run_method("pull_emp_details") - sal_slip.run_method("get_leave_details") - sal_slip.run_method("calculate_net_pay") + target.run_method("pull_emp_details") + target.run_method("get_leave_details") + target.run_method("calculate_net_pay") doc = get_mapped_doc("Salary Structure", source_name, { "Salary Structure": { diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 0551aaaf0c..aa87e1e582 100644 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -247,8 +247,7 @@ class SalesOrder(SellingController): return "order" if self.docstatus==1 else None def set_missing_values(source, target): - doc = frappe.get_doc(target) - doc.run_method("onload_post_render") + target.run_method("onload_post_render") @frappe.whitelist() def make_material_request(source_name, target_doc=None): @@ -316,9 +315,8 @@ def make_delivery_note(source_name, target_doc=None): @frappe.whitelist() def make_sales_invoice(source_name, target_doc=None): def set_missing_values(source, target): - doc = frappe.get_doc(target) - doc.is_pos = 0 - doc.run_method("onload_post_render") + target.is_pos = 0 + target.run_method("onload_post_render") def update_item(source, target, source_parent): target.amount = flt(source.amount) - flt(source.billed_amt) diff --git a/erpnext/selling/page/sales_browser/sales_browser.js b/erpnext/selling/page/sales_browser/sales_browser.js index adfbd00d91..950e3f61f4 100644 --- a/erpnext/selling/page/sales_browser/sales_browser.js +++ b/erpnext/selling/page/sales_browser/sales_browser.js @@ -5,18 +5,18 @@ pscript['onload_Sales Browser'] = function(wrapper){ frappe.ui.make_app_page({ parent: wrapper, }) - + wrapper.appframe.add_module_icon("Selling") - - wrapper.appframe.set_title_right('Refresh', function() { + + wrapper.appframe.set_title_right('Refresh', function() { wrapper.make_tree(); }); $(wrapper) .find(".layout-side-section") - .html('
    '+ - __('Click on a link to get options to expand get options ') + + .html('
    '+ + __('Click on a link to get options to expand get options ') + __('Add') + ' / ' + __('Edit') + ' / '+ __('Delete') + '.
    ') wrapper.make_tree = function() { @@ -26,7 +26,7 @@ pscript['onload_Sales Browser'] = function(wrapper){ args: {ctype: ctype}, callback: function(r) { var root = r.message[0]["value"]; - erpnext.sales_chart = new erpnext.SalesChart(ctype, root, + erpnext.sales_chart = new erpnext.SalesChart(ctype, root, $(wrapper) .find(".layout-main-section") .css({ @@ -36,7 +36,7 @@ pscript['onload_Sales Browser'] = function(wrapper){ } }); } - + wrapper.make_tree(); } @@ -61,17 +61,17 @@ erpnext.SalesChart = Class.extend({ frappe.boot.user.in_create.indexOf(this.ctype) !== -1; me.can_write = frappe.model.can_write(this.ctype); me.can_delete = frappe.model.can_delete(this.ctype); - + this.tree = new frappe.ui.Tree({ - parent: $(parent), + parent: $(parent), label: root, args: {ctype: ctype}, method: 'erpnext.selling.page.sales_browser.sales_browser.get_children', toolbar: [ {toggle_btn: true}, { - label:__("Edit"), - condition: function(node) { + label:__("Edit"), + condition: function(node) { return !node.root && me.can_read; }, click: function(node) { @@ -103,44 +103,44 @@ erpnext.SalesChart = Class.extend({ }); } } - + ] }); }, new_node: function() { var me = this; - + var fields = [ - {fieldtype:'Data', fieldname: 'name_field', + {fieldtype:'Data', fieldname: 'name_field', label:'New ' + me.ctype + ' Name', reqd:true}, - {fieldtype:'Select', fieldname:'is_group', label:'Group Node', options:'No\nYes', - description: __("Further nodes can be only created under 'Group' type nodes")}, + {fieldtype:'Select', fieldname:'is_group', label:'Group Node', options:'No\nYes', + description: __("Further nodes can be only created under 'Group' type nodes")}, {fieldtype:'Button', fieldname:'create_new', label:'Create New' } ] - + if(me.ctype == "Sales Person") { fields.splice(-1, 0, {fieldtype:'Link', fieldname:'employee', label:'Employee', options:'Employee', description: __("Please enter Employee Id of this sales parson")}); } - + // the dialog var d = new frappe.ui.Dialog({ title: __('New ') + __(me.ctype), fields: fields - }) - + }) + d.set_value("is_group", "No"); // create $(d.fields_dict.create_new.input).click(function() { var btn = this; var v = d.get_values(); if(!v) return; - + var node = me.tree.get_selected_node(); - + v.parent = node.label; v.ctype = me.ctype; - + return frappe.call({ method: 'erpnext.selling.page.sales_browser.sales_browser.add_node', args: v, @@ -152,9 +152,9 @@ erpnext.SalesChart = Class.extend({ node.toggle_node(); } } - } - }) + } + }); }); - d.show(); + d.show(); }, -}); \ No newline at end of file +}); diff --git a/erpnext/selling/page/sales_browser/sales_browser.py b/erpnext/selling/page/sales_browser/sales_browser.py index fcb270e5c5..41d9f199d1 100644 --- a/erpnext/selling/page/sales_browser/sales_browser.py +++ b/erpnext/selling/page/sales_browser/sales_browser.py @@ -11,28 +11,27 @@ def get_children(): frappe.local.form_dict['parent_field'] = 'parent_' + ctype.lower().replace(' ', '_') if not frappe.form_dict.get('parent'): frappe.local.form_dict['parent'] = '' - - return frappe.db.sql("""select name as value, + + return frappe.db.sql("""select name as value, if(is_group='Yes', 1, 0) as expandable from `tab%(ctype)s` where docstatus < 2 and ifnull(%(parent_field)s,'') = "%(parent)s" order by name""" % frappe.local.form_dict, as_dict=1) - + @frappe.whitelist() def add_node(): - # ctype = frappe.form_dict.get('ctype') + ctype = frappe.form_dict.get('ctype') parent_field = 'parent_' + ctype.lower().replace(' ', '_') name_field = ctype.lower().replace(' ', '_') + '_name' - - doclist = [{ - "doctype": ctype, - "__islocal": 1, + + doc = frappe.new_doc(ctype) + doc.update({ name_field: frappe.form_dict['name_field'], parent_field: frappe.form_dict['parent'], "is_group": frappe.form_dict['is_group'] - }] + }) if ctype == "Sales Person": - doclist[0]["employee"] = frappe.form_dict.get('employee') - - frappe.get_doc(doclist).save() \ No newline at end of file + doc.employee = frappe.form_dict.get('employee') + + doc.save() diff --git a/erpnext/setup/doctype/customer_group/customer_group.js b/erpnext/setup/doctype/customer_group/customer_group.js index 04670720df..03c5c2bfdf 100644 --- a/erpnext/setup/doctype/customer_group/customer_group.js +++ b/erpnext/setup/doctype/customer_group/customer_group.js @@ -1,6 +1,8 @@ // 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/Customer Group"; + cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.cscript.set_root_readonly(doc); } @@ -22,5 +24,5 @@ cur_frm.fields_dict['parent_customer_group'].get_query = function(doc,cdt,cdn) { filters: { 'is_group': "Yes" } - } -} \ No newline at end of file + } +} diff --git a/erpnext/setup/doctype/item_group/item_group.js b/erpnext/setup/doctype/item_group/item_group.js index 589039e245..43a7117083 100644 --- a/erpnext/setup/doctype/item_group/item_group.js +++ b/erpnext/setup/doctype/item_group/item_group.js @@ -1,6 +1,7 @@ // 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); @@ -33,4 +34,4 @@ cur_frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) { ['Item Group', 'name', '!=', doc.item_group_name] ] } -} \ No newline at end of file +} diff --git a/erpnext/setup/doctype/sales_person/sales_person.js b/erpnext/setup/doctype/sales_person/sales_person.js index a87279f666..b342485ee5 100644 --- a/erpnext/setup/doctype/sales_person/sales_person.js +++ b/erpnext/setup/doctype/sales_person/sales_person.js @@ -1,6 +1,8 @@ // 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/Sales Person"; + cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.cscript.set_root_readonly(doc); } @@ -33,4 +35,4 @@ cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = f cur_frm.fields_dict.employee.get_query = function(doc, cdt, cdn) { return { query: "erpnext.controllers.queries.employee_query" } -} \ No newline at end of file +} diff --git a/erpnext/setup/doctype/territory/territory.js b/erpnext/setup/doctype/territory/territory.js index 4b7b2f68c8..f870641662 100644 --- a/erpnext/setup/doctype/territory/territory.js +++ b/erpnext/setup/doctype/territory/territory.js @@ -1,6 +1,8 @@ // 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/Territory"; + cur_frm.cscript.refresh = function(doc, cdt, cdn) { cur_frm.cscript.set_root_readonly(doc); } @@ -26,7 +28,7 @@ cur_frm.fields_dict['parent_territory'].get_query = function(doc,cdt,cdn) { } -// ******************** ITEM Group ******************************** +// ******************** ITEM Group ******************************** cur_frm.fields_dict['target_details'].grid.get_field("item_group").get_query = function(doc, cdt, cdn) { return{ filters:{ 'is_group': "No"}