From 195d579361e9694ea2958c0687ed2c1e4b34f493 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Thu, 24 Jan 2013 15:07:24 +0530 Subject: [PATCH] check customer/customer_group with same name while creating customer_group/customer --- selling/doctype/customer/customer.py | 8 ++++++++ setup/doctype/customer_group/customer_group.py | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/selling/doctype/customer/customer.py b/selling/doctype/customer/customer.py index 8218b19bed..6aab938ed9 100644 --- a/selling/doctype/customer/customer.py +++ b/selling/doctype/customer/customer.py @@ -172,6 +172,8 @@ class DocType(TransactionBase): pass def on_update(self): + self.validate_name_with_customer_group() + self.update_lead_status() # create account head self.create_account_head() @@ -179,6 +181,12 @@ class DocType(TransactionBase): self.update_credit_days_limit() #create address and contact from lead self.create_lead_address_contact() + + def validate_name_with_customer_group(self): + if webnotes.conn.exists("Customer Group", self.doc.name): + webnotes.msgprint("An Customer Group exists with same name (%s), \ + please change the Customer name or rename the Customer Group" % + self.doc.name, raise_exception=1) def delete_customer_address(self): for rec in sql("select * from `tabAddress` where customer='%s'" %(self.doc.name), as_dict=1): diff --git a/setup/doctype/customer_group/customer_group.py b/setup/doctype/customer_group/customer_group.py index f13690d93d..a3baaa9926 100644 --- a/setup/doctype/customer_group/customer_group.py +++ b/setup/doctype/customer_group/customer_group.py @@ -37,6 +37,15 @@ class DocType(DocTypeNestedSet): To untrash please go to Setup -> Recycle Bin.""" % (self.doc.customer_group_name), raise_exception = 1) + def on_update(self): + self.validate_name_with_customer() + + def validate_name_with_customer(self): + if webnotes.conn.exists("Customer", self.doc.name): + webnotes.msgprint("An Customer exists with same name (%s), \ + please change the Customer Group name or rename the Customer" % + self.doc.name, raise_exception=1) + def on_trash(self): cust = sql("select name from `tabCustomer` where ifnull(customer_group, '') = %s", self.doc.name)