Odoo Help


check whether a customer name already exists

sneha antony
on 4/23/14, 6:57 AM 3,482 views

While creating customers directly or through various interfaces, multiple customers with the same name are being created twice and thrice.Is there any option to give a validation to check a newly entered customer name exists or not?


Jagdish Panchal

--Jagdish Panchal--

| 5 4 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

Jagdish Panchal
On 4/23/14, 7:01 AM


You can add _sql_constraints for name field.

Create partner.py file add below code in py file

class res_partner(osv.osv):
    _inherit = 'res.partner'

def create(self, cr, uid, vals, context=None):
    if context is None:   
        context = {}
    if vals.has_key('name'):
        exis_data_id = self.search(cr, uid, [('name','=', vals['name'])])
        if exis_data_id:
            raise osv.except_osv(_('Invalid Action!'), _('Name already exist.'))
    return super(res_partner ,self).create(cr, uid, vals, context)


What _sql_constraints for name field are to be added?In which file can I find the name field as i was not able to find it out in the sales module.

sneha antony
on 4/23/14, 8:41 AM

update ans please check it.

Jagdish Panchal
on 4/23/14, 8:54 AM

Which is the file to which this code has to be added?

sneha antony
on 4/23/14, 9:03 AM

for res.partner object

on 4/23/14, 9:10 AM

Where your code related res.partner

Jagdish Panchal
on 4/23/14, 9:12 AM

in partner.py file.

sneha antony
on 4/23/14, 9:16 AM

yes in partner.py file.

Jagdish Panchal
on 4/23/14, 9:38 AM

but the existing module cannot be edited no?New class are to be added in newly created module

sneha antony
on 4/23/14, 9:46 AM

Then add it in newly created module. where you define res.partner class

Jagdish Panchal
on 4/23/14, 9:56 AM

which are the files to be included in the new module?how to link the new module with the res.partner class.What are the contents to be given in the files created for the new folder?

sneha antony
on 4/23/14, 10:04 AM

I have update ans pls check it

Jagdish Panchal
on 4/23/14, 10:13 AM

Where is the partner.py to be created?

sneha antony
on 4/23/14, 10:28 AM

Create new module and add this file put newly created module in addons directory update module list and install it.

Jagdish Panchal
on 4/23/14, 10:35 AM

I installed a new module customer_validation for the above purpose and added the code in py file but now the issue is the validation does not work.Still I can add a name and save it which already exists.

sneha antony
on 4/24/14, 3:09 AM

update answer check it

Jagdish Panchal
on 4/24/14, 3:20 AM

still the duplicate entries can be made after the code has been updated.The same name can be entered and saved.

sneha antony
on 4/24/14, 3:30 AM

i have tested this code @ my end its work fine. It not allow to enter same name.

Jagdish Panchal
on 4/24/14, 3:38 AM

let me explain what all i have done.I first created a new module with files _init_.py , _openerp_.py and py file which includes the given code.

sneha antony
on 4/24/14, 3:42 AM

_init_.py contains import (file name of py file)

sneha antony
on 4/24/14, 3:43 AM

_openerp_.py contains general data as in other modules.And the .py file contains the above updated code.And then the module was added to the addons folder and the openerp was updated .When it was listed in the Installed modules list,it was installed to the modules and once again the modules list was updated so that it can be used.After doing all these procedures when i tested by entering the customer name that already existed,the expected validation didnt work

sneha antony
on 4/24/14, 3:44 AM

hi done ?

Jagdish Panchal
on 4/24/14, 10:09 AM

No Jack still in dilemma.validation not working.

sneha antony
on 4/25/14, 2:29 AM

Create module __init__.py, __openerp__.py and partner.py add code in partern.py install module it will work.

Jagdish Panchal
on 4/25/14, 3:14 AM

Omal Bastin

--Omal Bastin--

| 6 6 8
Kochi, Kerala, India
--Omal Bastin--

Swiming deep into openERP/ODOO

Omal Bastin
On 7/31/14, 9:47 AM

The name for a customer will not be unique. There wll be so many customers having same name. One thing you can do is to make the reference field (ref) required and add a unique constraint for that field.
For example in my company there are two customers with the name Sunil Kumar. So we provide different reference for both the customers. Like CustRef#0036 and CustRef#0665

Hi,....How ref is used can u explain with an example..Thx in advance

on 7/31/14, 11:04 AM

For instance, you could try providing a customer ID value generated @ reference field using SEQUENCE. So, that it can be used unique and also there can be many customers with a same name.

Atchuthan - Technical Consultant, Sodexis Inc
on 7/31/14, 11:35 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 4/23/14, 6:57 AM
Seen: 3482 times
Last updated: 3/16/15, 8:10 AM