This question has been flagged

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?

Avatar
Discard
Best Answer

Hi,
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

Avatar
Discard

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

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.

Best Answer

Hi,

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)

res_partner()
Avatar
Discard
Author

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.

update ans please check it.

Author

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

for res.partner object

Where your code related res.partner

Author

in partner.py file.

yes in partner.py file.

Author

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

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

Author

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?

I have update ans pls check it

Author

Where is the partner.py to be created?

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

Author

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.

update answer check it

Author

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

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

Author

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.

Author

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

Author

_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

Author

No Jack still in dilemma.validation not working.

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