more refactoring to renaming

This commit is contained in:
Rushabh Mehta
2012-12-06 12:09:52 +05:30
parent 2249d9d858
commit 76c4f61ffb
9 changed files with 812 additions and 971 deletions

View File

@@ -212,7 +212,7 @@ class DocType(TransactionBase):
if self.doc.lead_name:
sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
def on_rename(self,newdn,olddn):
def on_rename(self, new, old):
#update customer_name if not naming series
if get_defaults().get('cust_master_name') == 'Customer Name':
update_fields = [
@@ -235,13 +235,14 @@ class DocType(TransactionBase):
('Support Ticket', 'customer'),
('Task', 'customer')]
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))
sql("""update `tab%s` set customer_name = %s
where `%s` = %s""" % (rec[0], "%s" ,rec[1], "%s"), (new, old))
from webnotes.model.rename_doc import rename_doc
rename_doc("Account", old_account, newdn)
for account in webnotes.conn.sql("""select name, account_name from
tabAccount where master_name=%s and master_type='Customer'""", old, as_dict=1):
if account.account_name != new:
webnotes.rename_doc("Account", account.name, new)
#update master_name in doctype account
webnotes.conn.sql("""update `tabAccount` set master_name = %s,
master_type = 'Customer' where master_name = %s""", (new,old))