From ef6a76f8aa7cb96611ede7b33bc9f907508c37fe Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Mon, 3 Dec 2012 15:45:03 +0530 Subject: [PATCH] fixes in renaming account, supplier, customer; fixes in accounts browser; fixes in customer address contact fetching in opportunity --- accounts/doctype/account/account.py | 17 ++++++++++------- .../page/accounts_browser/accounts_browser.js | 16 ++++++++++++---- buying/doctype/supplier/supplier.py | 6 ++++++ selling/doctype/customer/customer.py | 7 +++++++ selling/doctype/opportunity/opportunity.js | 17 +++++++++++++++-- 5 files changed, 50 insertions(+), 13 deletions(-) diff --git a/accounts/doctype/account/account.py b/accounts/doctype/account/account.py index b3f9053210..28191db87d 100644 --- a/accounts/doctype/account/account.py +++ b/accounts/doctype/account/account.py @@ -78,7 +78,7 @@ class DocType: def validate_root_details(self): #does not exists parent if webnotes.conn.exists("Account", self.doc.name): - if not self.doc.get_value("Account", self.doc.name, "parent_account"): + if not webnotes.conn.get_value("Account", self.doc.name, "parent_account"): webnotes.msgprint("Root cannot be edited.", raise_exception=1) def convert_group_to_ledger(self): @@ -182,10 +182,13 @@ class DocType: def on_rename(self,newdn,olddn): company_abbr = sql("select tc.abbr from `tabAccount` ta, `tabCompany` tc where ta.company = tc.name and ta.name=%s", olddn)[0][0] - newdnchk = newdn.split(" - ") + parts = newdn.split(" - ") - if newdnchk[-1].lower() != company_abbr.lower(): - msgprint("Please add company abbreviation %s" %(company_abbr), raise_exception=1) - else: - account_name = " - ".join(newdnchk[:-1]) - sql("update `tabAccount` set account_name = '%s' where name = '%s'" %(account_name,olddn)) + if parts[-1].lower() != company_abbr.lower(): + parts.append(company_abbr) + + account_name = " - ".join(parts[:-1]) + sql("update `tabAccount` set account_name = '%s' where name = '%s'" % \ + (account_name,olddn)) + + return " - ".join(parts) diff --git a/accounts/page/accounts_browser/accounts_browser.js b/accounts/page/accounts_browser/accounts_browser.js index 3df3770429..2d59a466ca 100644 --- a/accounts/page/accounts_browser/accounts_browser.js +++ b/accounts/page/accounts_browser/accounts_browser.js @@ -38,6 +38,7 @@ pscript['onload_Accounts Browser'] = function(wrapper){ .change(function() { var ctype = wn.get_route()[1] || 'Account'; erpnext.account_chart = new erpnext.AccountsChart(ctype, $(this).val(), wrapper); + pscript.set_title(wrapper, ctype, $(this).val()); }) .appendTo(wrapper.appframe.$w.find('.appframe-toolbar')); @@ -60,16 +61,23 @@ pscript['onload_Accounts Browser'] = function(wrapper){ }); } +pscript.set_title = function(wrapper, ctype, val) { + if(val) { + wrapper.appframe.set_title('Chart of '+ctype+'s' + " - " + cstr(val)); + } else { + wrapper.appframe.set_title('Chart of '+ctype+'s'); + } +} + pscript['onshow_Accounts Browser'] = function(wrapper){ // set route var ctype = wn.get_route()[1] || 'Account'; - wrapper.appframe.set_title('Chart of '+ctype+'s'); - if(erpnext.account_chart && erpnext.account_chart.ctype != ctype) { wrapper.$company_select.change(); - } - + } + + pscript.set_title(wrapper, ctype); } erpnext.AccountsChart = Class.extend({ diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py index 63106539e5..0c9d056b3b 100644 --- a/buying/doctype/supplier/supplier.py +++ b/buying/doctype/supplier/supplier.py @@ -173,5 +173,11 @@ class DocType(TransactionBase): for rec in update_fields: sql("update `tab%s` set supplier_name = '%s' where %s = '%s'" %(rec[0],newdn,rec[1],olddn)) + old_account = webnotes.conn.get_value("Account", {"master_type": "Supplier", + "master_name": olddn}) + #update master_name in doctype account sql("update `tabAccount` set master_name = '%s', master_type = 'Supplier' where master_name = '%s'" %(newdn,olddn)) + + from webnotes.model.rename_doc import rename_doc + rename_doc("Account", old_account, newdn) diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py index fa16f45e1e..03a8c7ea84 100644 --- a/selling/doctype/customer/customer.py +++ b/selling/doctype/customer/customer.py @@ -125,6 +125,7 @@ class DocType(TransactionBase): parent_account = self.get_receivables_group() arg = {'account_name':self.doc.name,'parent_account': parent_account, 'group_or_ledger':'Ledger', 'company':self.doc.company,'account_type':'','tax_rate':'0','master_type':'Customer','master_name':self.doc.name,'address':self.doc.address} # create + ac = get_obj('GL Control').add_ac(cstr(arg)) msgprint("Account Head created for "+ac) else : @@ -236,5 +237,11 @@ class DocType(TransactionBase): for rec in update_fields: sql("update `tab%s` set customer_name = '%s' where %s = '%s'" %(rec[0],newdn,rec[1],olddn)) + old_account = webnotes.conn.get_value("Account", {"master_type": "Customer", + "master_name": olddn}) + #update master_name in doctype account sql("update `tabAccount` set master_name = '%s', master_type = 'Customer' where master_name = '%s'" %(newdn,olddn)) + + from webnotes.model.rename_doc import rename_doc + rename_doc("Account", old_account, newdn) diff --git a/selling/doctype/opportunity/opportunity.js b/selling/doctype/opportunity/opportunity.js index 3da2ac88bb..67a6e24675 100644 --- a/selling/doctype/opportunity/opportunity.js +++ b/selling/doctype/opportunity/opportunity.js @@ -94,8 +94,21 @@ cur_frm.cscript.lead_cust_show = function(doc,cdt,cdn){ // customer cur_frm.cscript.customer = function(doc,dt,dn) { - if(doc.customer) get_server_fields('get_default_customer_address', JSON.stringify({customer: doc.customer}),'', doc, dt, dn, 1); - if(doc.customer) unhide_field(['customer_name','customer_address','contact_person','address_display','contact_display','contact_mobile','contact_email','territory','customer_group']); + if(doc.customer) { + cur_frm.call({ + method: "get_default_customer_address", + args: { customer: doc.customer }, + callback: function(r) { + if(!r.exc) { + cur_frm.refresh(); + } + } + }); + + unhide_field(["customer_name", "customer_address", "contact_person", + "address_display", "contact_display", "contact_mobile", "contact_email", + "territory", "customer_group"]); + } } cur_frm.cscript.customer_address = cur_frm.cscript.contact_person = function(doc,dt,dn) {