From abefa3fd40440a92a65ca4cf0cc99f0dc5792849 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Tue, 10 Dec 2013 14:22:52 +0530 Subject: [PATCH] [fix] [minor] supplier & customer rename fix --- buying/doctype/supplier/supplier.py | 30 ++++++++++++++++++---------- selling/doctype/customer/customer.py | 30 ++++++++++++++++++---------- 2 files changed, 40 insertions(+), 20 deletions(-) diff --git a/buying/doctype/supplier/supplier.py b/buying/doctype/supplier/supplier.py index 48bb9c276c..503ec8a1dd 100644 --- a/buying/doctype/supplier/supplier.py +++ b/buying/doctype/supplier/supplier.py @@ -27,6 +27,14 @@ class DocType(TransactionBase): else: self.doc.name = make_autoname(self.doc.naming_series + '.#####') + def update_address(self): + webnotes.conn.sql("""update `tabAddress` set supplier_name=%s + where supplier=%s""", (self.doc.supplier_name, self.doc.name)) + + def update_contact(self): + webnotes.conn.sql("""update `tabContact` set supplier_name=%s + where supplier=%s""", (self.doc.supplier_name, self.doc.name)) + def update_credit_days_limit(self): webnotes.conn.sql("""update tabAccount set credit_days = %s where name = %s""", (cint(self.doc.credit_days), self.doc.name + " - " + self.get_company_abbr())) @@ -35,6 +43,9 @@ class DocType(TransactionBase): if not self.doc.naming_series: self.doc.naming_series = '' + self.update_address() + self.update_contact() + # create account head self.create_account_head() @@ -151,20 +162,19 @@ class DocType(TransactionBase): def before_rename(self, olddn, newdn, merge=False): from accounts.utils import rename_account_for rename_account_for("Supplier", olddn, newdn, merge) - self.rename_address(olddn, newdn) - self.rename_contact(olddn, newdn) - def rename_address(self, olddn, newdn): - webnotes.conn.sql("""update `tabAddress` set supplier_name=%s, - address_title=%s where supplier=%s""", (newdn, newdn, olddn)) - - def rename_contact(self,olddn, newdn): - webnotes.conn.sql("""update `tabContact` set supplier_name=%s - where supplier=%s""", (newdn, olddn)) - def after_rename(self, olddn, newdn, merge=False): + condition = value = '' if webnotes.defaults.get_global_default('supp_master_name') == 'Supplier Name': webnotes.conn.set(self.doc, "supplier_name", newdn) + self.update_contact() + condition = ", supplier_name=%s" + value = newdn + self.update_supplier_address(newdn, condition, value) + + def update_supplier_address(self, newdn, condition, value): + webnotes.conn.sql("""update `tabAddress` set address_title=%s %s + where supplier=%s""" % ('%s', condition, '%s'), (newdn, value, newdn)) @webnotes.whitelist() def get_dashboard_info(supplier): diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py index 356628a6b9..71116b33b1 100644 --- a/selling/doctype/customer/customer.py +++ b/selling/doctype/customer/customer.py @@ -47,6 +47,14 @@ class DocType(TransactionBase): if self.doc.lead_name: webnotes.conn.sql("update `tabLead` set status='Converted' where name = %s", self.doc.lead_name) + def update_address(self): + webnotes.conn.sql("""update `tabAddress` set customer_name=%s where customer=%s""", + (self.doc.customer_name, self.doc.name)) + + def update_contact(self): + webnotes.conn.sql("""update `tabContact` set customer_name=%s where customer=%s""", + (self.doc.customer_name, self.doc.name)) + def create_account_head(self): if self.doc.company : abbr = self.get_company_abbr() @@ -99,6 +107,9 @@ class DocType(TransactionBase): self.validate_name_with_customer_group() self.update_lead_status() + self.update_address() + self.update_contact() + # create account head self.create_account_head() # update credit days and limit in account @@ -146,20 +157,19 @@ class DocType(TransactionBase): def before_rename(self, olddn, newdn, merge=False): from accounts.utils import rename_account_for rename_account_for("Customer", olddn, newdn, merge) - self.rename_address(olddn, newdn) - self.rename_contact(olddn, newdn) - - def rename_address(self, olddn, newdn): - webnotes.conn.sql("""update `tabAddress` set customer_name=%s, - address_title=%s where customer=%s""", (newdn, newdn, olddn)) - - def rename_contact(self,olddn, newdn): - webnotes.conn.sql("""update `tabContact` set customer_name=%s - where customer=%s""", (newdn, olddn)) def after_rename(self, olddn, newdn, merge=False): + condition = value = '' if webnotes.defaults.get_global_default('cust_master_name') == 'Customer Name': webnotes.conn.set(self.doc, "customer_name", newdn) + self.update_contact() + condition = ", customer_name=%s" + value = newdn + self.update_customer_address(newdn, condition, value) + + def update_customer_address(self, newdn, condition, value): + webnotes.conn.sql("""update `tabAddress` set address_title=%s %s + where customer=%s""" % ('%s', condition, '%s'), (newdn, value, newdn)) @webnotes.whitelist() def get_dashboard_info(customer):