From 39f8c3cefe9637d08570b584524212d59cfe9602 Mon Sep 17 00:00:00 2001 From: Ravi Dey Date: Mon, 20 Jun 2011 16:27:55 +0530 Subject: [PATCH] customer/supplier address deletion fix --- crm/doctype/customer/customer.py | 11 ++++++++++- srm/doctype/supplier/supplier.py | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/crm/doctype/customer/customer.py b/crm/doctype/customer/customer.py index 3d2fa59335..eba2fc0389 100644 --- a/crm/doctype/customer/customer.py +++ b/crm/doctype/customer/customer.py @@ -214,8 +214,17 @@ class DocType: #create address and contact from lead self.create_lead_address_contact() + def delete_customer_address(self): + for rec in sql("select * from `tabAddress` where customer='%s'" %(self.doc.name), as_dict=1): + sql("delete from `tabAddress` where name=%s",(rec['name'])) + + def delete_customer_contact(self): + for rec in sql("select * from `tabContact` where customer='%s'" %(self.doc.name), as_dict=1): + sql("delete from `tabContact` where name=%s",(rec['name'])) # ******************************************************* on trash ********************************************************* - def on_trash(self): + def on_trash(self): + self.delete_customer_address() + self.delete_customer_contact() if self.doc.lead_name: sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name) diff --git a/srm/doctype/supplier/supplier.py b/srm/doctype/supplier/supplier.py index e6db6c326e..31d5b3dff0 100644 --- a/srm/doctype/supplier/supplier.py +++ b/srm/doctype/supplier/supplier.py @@ -134,3 +134,15 @@ class DocType: return contact_details else: return '' + + def delete_supplier_address(self): + for rec in sql("select * from `tabAddress` where supplier='%s'" %(self.doc.name), as_dict=1): + sql("delete from `tabAddress` where name=%s",(rec['name'])) + + def delete_supplier_contact(self): + for rec in sql("select * from `tabContact` where supplier='%s'" %(self.doc.name), as_dict=1): + sql("delete from `tabContact` where name=%s",(rec['name'])) + + def on_trash(self): + self.delete_supplier_address() + self.delete_supplier_contact()