From d2b3fe8a0271c04cb5d2908984a520f751671bde Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 25 Jul 2013 16:29:15 +0530 Subject: [PATCH 1/4] [fix] [minor] get_query for cost center form --- accounts/doctype/cost_center/cost_center.js | 65 +++++++++++---------- 1 file changed, 34 insertions(+), 31 deletions(-) diff --git a/accounts/doctype/cost_center/cost_center.js b/accounts/doctype/cost_center/cost_center.js index ed60cc01f9..96af1cfc96 100644 --- a/accounts/doctype/cost_center/cost_center.js +++ b/accounts/doctype/cost_center/cost_center.js @@ -14,6 +14,40 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +wn.provide("erpnext.accounts"); +erpnext.accounts.CostCenterController = wn.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")) { + this.frm.set_query("account", "budget_details", function() { + return { + filters:[ + ['Account', 'company', '=', me.frm.doc.company], + ['Account', 'is_pl_account', '=', 'Yes'], + ['Account', 'debit_or_credit', '=', 'Debit'], + ['Account', 'group_or_ledger', '!=', 'Group'], + ] + } + }); + } + + this.frm.set_query("parent_cost_center", function() { + return { + filters:[ + ['Cost Center', 'group_or_ledger', '=', 'Group'], + ['Cost Center', 'company', '=', me.frm.doc.company], + ] + } + }); + } +}); + +$.extend(cur_frm.cscript, new erpnext.accounts.CostCenterController({frm: cur_frm})); + cur_frm.cscript.refresh = function(doc, cdt, cdn) { var intro_txt = ''; cur_frm.toggle_display('cost_center_name', doc.__islocal); @@ -33,39 +67,12 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) { function() { wn.set_route("Accounts Browser", "Cost Center"); }, 'icon-sitemap') } -//Account filtering for cost center -cur_frm.fields_dict['budget_details'].grid.get_field('account').get_query = function(doc) { - var mydoc = locals[this.doctype][this.docname]; - return{ - filters:[ - ['Account', 'company', '=', doc.company], - ['Account', 'is_pl_account', '=', 'Yes'], - ['Account', 'debit_or_credit', '=', 'Debit'], - ['Account', 'group_or_ledger', '!=', 'Group'], - ['Account', 'group_or_ledger', 'is not', 'NULL'] - ] - } -} - -cur_frm.fields_dict['parent_cost_center'].get_query = function(doc){ - return{ - filters:[ - ['Cost Center', 'group_or_ledger', '=', 'Group'], - ['Cost Center', 'company', '=', doc.company], - ['Cost Center', 'company', 'is not', 'NULL'] - ] - } -} - -//parent cost center cur_frm.cscript.parent_cost_center = function(doc,cdt,cdn){ if(!doc.company){ alert('Please enter company name first'); } } -// Hide/unhide group or ledger -// ----------------------------------------- cur_frm.cscript.hide_unhide_group_ledger = function(doc) { if (cstr(doc.group_or_ledger) == 'Group') { cur_frm.add_custom_button('Convert to Ledger', @@ -76,8 +83,6 @@ cur_frm.cscript.hide_unhide_group_ledger = function(doc) { } } -// Convert group to ledger -// ----------------------------------------- cur_frm.cscript.convert_to_ledger = function(doc, cdt, cdn) { $c_obj(cur_frm.get_doclist(),'convert_group_to_ledger','',function(r,rt) { if(r.message == 1) { @@ -86,8 +91,6 @@ cur_frm.cscript.convert_to_ledger = function(doc, cdt, cdn) { }); } -// Convert ledger to group -// ----------------------------------------- cur_frm.cscript.convert_to_group = function(doc, cdt, cdn) { $c_obj(cur_frm.get_doclist(),'convert_ledger_to_group','',function(r,rt) { if(r.message == 1) { From 2b1d33f1783e9e53f24c710a0f44c69958a8b751 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 25 Jul 2013 17:17:47 +0530 Subject: [PATCH 2/4] [minor] [cleanup] [issue] webnotes/erpnext#438 - change user_type Partner to Website User --- .../july_2013/p10_change_partner_user_to_website_user.py | 9 +++++++++ patches/march_2013/p09_unset_user_type_partner.py | 6 ------ patches/patch_list.py | 2 +- startup/event_handlers.py | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 patches/july_2013/p10_change_partner_user_to_website_user.py delete mode 100644 patches/march_2013/p09_unset_user_type_partner.py diff --git a/patches/july_2013/p10_change_partner_user_to_website_user.py b/patches/july_2013/p10_change_partner_user_to_website_user.py new file mode 100644 index 0000000000..50bc67114a --- /dev/null +++ b/patches/july_2013/p10_change_partner_user_to_website_user.py @@ -0,0 +1,9 @@ +import webnotes + +def execute(): + webnotes.conn.sql("""update `tabProfile` set user_type="Website User" where user_type="Partner" """) + webnotes.conn.sql("""update `tabProfile` set user_type="System User" where ifnull(user_type, "")="" """) + + webnotes.conn.sql("""update `tabProfile` set user_type='System User' + where user_type='Website User' and exists (select name from `tabUserRole` + where parent=`tabProfile`.name)""") \ No newline at end of file diff --git a/patches/march_2013/p09_unset_user_type_partner.py b/patches/march_2013/p09_unset_user_type_partner.py deleted file mode 100644 index cc5cdce5c2..0000000000 --- a/patches/march_2013/p09_unset_user_type_partner.py +++ /dev/null @@ -1,6 +0,0 @@ -import webnotes - -def execute(): - webnotes.conn.sql("""update `tabProfile` set user_type='System User' - where user_type='Partner' and exists (select name from `tabUserRole` - where parent=`tabProfile`.name)""") \ No newline at end of file diff --git a/patches/patch_list.py b/patches/patch_list.py index d622cd648c..9b6bb0f2dd 100644 --- a/patches/patch_list.py +++ b/patches/patch_list.py @@ -194,7 +194,6 @@ patch_list = [ "execute:webnotes.reload_doc('website', 'doctype', 'web_page') #2013-03-25", "execute:webnotes.reload_doc('setup', 'doctype', 'sales_partner') #2013-06-25", "execute:webnotes.conn.set_value('Email Settings', None, 'send_print_in_body_and_attachment', 1)", - "patches.march_2013.p09_unset_user_type_partner", "patches.march_2013.p10_set_fiscal_year_for_stock", "patches.march_2013.p10_update_against_expense_account", "patches.march_2013.p11_update_attach_files", @@ -262,4 +261,5 @@ patch_list = [ "execute:webnotes.reload_doc('stock', 'Print Format', 'Delivery Note Spartan') # 2013-07-22", "patches.july_2013.p08_custom_print_format_net_total_export", "patches.july_2013.p09_remove_website_pyc", + "patches.july_2013.p10_change_partner_user_to_website_user", ] \ No newline at end of file diff --git a/startup/event_handlers.py b/startup/event_handlers.py index 3f145421c0..d19f9e6a1c 100644 --- a/startup/event_handlers.py +++ b/startup/event_handlers.py @@ -30,7 +30,7 @@ def on_login_post_session(login_manager): login_manager.user=='Administrator' and '#8CA2B3' or '#1B750D') webnotes.conn.commit() - if webnotes.conn.get_value("Profile", webnotes.session.user, "user_type") == "Partner": + if webnotes.conn.get_value("Profile", webnotes.session.user, "user_type") == "Website User": from website.helpers.cart import set_cart_count set_cart_count() From bfe0c47805181de2acb01051a07344209239abe4 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 25 Jul 2013 17:23:00 +0530 Subject: [PATCH 3/4] [fix] [minor] budget distribution validation --- .../budget_distribution.py | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/accounts/doctype/budget_distribution/budget_distribution.py b/accounts/doctype/budget_distribution/budget_distribution.py index f2fff5a0ac..00d11f94f6 100644 --- a/accounts/doctype/budget_distribution/budget_distribution.py +++ b/accounts/doctype/budget_distribution/budget_distribution.py @@ -8,11 +8,11 @@ # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . from __future__ import unicode_literals import webnotes @@ -20,26 +20,26 @@ import webnotes from webnotes.utils import flt from webnotes.model.doc import addchild from webnotes.model.bean import getlist -from webnotes import msgprint +from webnotes import msgprint, _ class DocType: - def __init__(self,doc,doclist=[]): - self.doc,self.doclist = doc,doclist - - def get_months(self): - month_list = ['January','February','March','April','May','June','July','August','September', + def __init__(self,doc,doclist=[]): + self.doc,self.doclist = doc,doclist + + def get_months(self): + month_list = ['January','February','March','April','May','June','July','August','September', 'October','November','December'] - idx =1 - for m in month_list: - mnth = addchild(self.doc, 'budget_distribution_details', - 'Budget Distribution Detail', self.doclist) - mnth.month = m or '' - mnth.idx = idx - idx += 1 - - def validate(self): - total = 0 - for d in getlist(self.doclist,'budget_distribution_details'): - total = flt(total) + flt(d.percentage_allocation) - if total != 100: - msgprint("Percentage Allocation should be equal to 100%%. Currently it is %s%%" % total, raise_exception=1) + idx =1 + for m in month_list: + mnth = addchild(self.doc, 'budget_distribution_details', + 'Budget Distribution Detail', self.doclist) + mnth.month = m or '' + mnth.idx = idx + idx += 1 + + def validate(self): + total = sum([flt(d.percentage_allocation, 2) for d in self.doclist.get( + {"parentfield": "budget_distribution_details"})]) + + if total != 100.0: + msgprint(_("Percentage Allocation should be equal to ") + "100%", raise_exception=1) \ No newline at end of file From f2045fb92e6864d5525e54d2ac0f1497acb05c3e Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 25 Jul 2013 17:46:02 +0530 Subject: [PATCH 4/4] [fix] [minor] set customer/supplier defaults --- .../purchase_invoice/purchase_invoice.py | 4 ++-- controllers/buying_controller.py | 7 +----- manufacturing/doctype/bom/bom.py | 7 +++--- utilities/transaction_base.py | 22 ++++++++++++++++--- 4 files changed, 26 insertions(+), 14 deletions(-) diff --git a/accounts/doctype/purchase_invoice/purchase_invoice.py b/accounts/doctype/purchase_invoice/purchase_invoice.py index aa82492baa..05723ce608 100644 --- a/accounts/doctype/purchase_invoice/purchase_invoice.py +++ b/accounts/doctype/purchase_invoice/purchase_invoice.py @@ -89,11 +89,11 @@ class DocType(BuyingController): return ret def set_supplier_defaults(self): - self.doc.fields.update(self.get_cust()) + self.doc.fields.update(self.get_supplier()) self.doc.fields.update(self.get_credit_to()) super(DocType, self).set_supplier_defaults() - def get_cust(self): + def get_supplier(self): ret = {} if self.doc.credit_to: acc = webnotes.conn.get_value('Account',self.doc.credit_to,['master_name', 'credit_days']) diff --git a/controllers/buying_controller.py b/controllers/buying_controller.py index a44ceba9c3..47c28f504d 100644 --- a/controllers/buying_controller.py +++ b/controllers/buying_controller.py @@ -47,17 +47,12 @@ class BuyingController(StockController): # set contact and address details for supplier, if they are not mentioned if self.doc.supplier and not (self.doc.contact_person and self.doc.supplier_address): - for fieldname, val in self.get_default_address_and_contact("supplier").items(): + for fieldname, val in self.get_supplier_defaults().items(): if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): self.doc.fields[fieldname] = val self.set_missing_item_details(get_item_details) - def set_supplier_defaults(self): - for fieldname, val in self.get_default_address_and_contact("supplier").items(): - if self.meta.get_field(fieldname): - self.doc.fields[fieldname] = val - def get_purchase_tax_details(self): self.doclist = self.doc.clear_table(self.doclist, "purchase_tax_details") self.set_taxes("purchase_tax_details", "purchase_other_charges") diff --git a/manufacturing/doctype/bom/bom.py b/manufacturing/doctype/bom/bom.py index 94f3d20ec3..7dba6ea281 100644 --- a/manufacturing/doctype/bom/bom.py +++ b/manufacturing/doctype/bom/bom.py @@ -97,9 +97,10 @@ class DocType: """ Get raw material details like uom, desc and rate""" if not args: args = webnotes.form_dict.get('args') - - import json - args = json.loads(args) + + if isinstance(args, basestring): + import json + args = json.loads(args) item = self.get_item_det(args['item_code']) self.validate_rm_item(item) diff --git a/utilities/transaction_base.py b/utilities/transaction_base.py index 2900bf6ec3..14c23b8588 100644 --- a/utilities/transaction_base.py +++ b/utilities/transaction_base.py @@ -94,8 +94,10 @@ class TransactionBase(StatusUpdater): webnotes.conn.get_value("Customer Group", self.doc.customer_group, "default_price_list") or \ self.doc.price_list - self.doc.fields.update(customer_defaults) - + for fieldname, val in customer_defaults.items(): + if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): + self.doc.fields[fieldname] = val + if self.meta.get_field("sales_team"): self.set_sales_team_for_customer() @@ -121,7 +123,21 @@ class TransactionBase(StatusUpdater): # add child self.doclist.append(sales_person) - + + def get_supplier_defaults(self): + out = self.get_default_address_and_contact("supplier") + + supplier = webnotes.doc("Supplier", self.doc.supplier) + out["supplier_name"] = supplier.supplier_name + out["currency"] = supplier.default_currency + + return out + + def set_supplier_defaults(self): + for fieldname, val in self.get_supplier_defaults().items(): + if not self.doc.fields.get(fieldname) and self.meta.get_field(fieldname): + self.doc.fields[fieldname] = val + def get_lead_defaults(self): out = self.get_default_address_and_contact("lead")