Odoo Help

Welcome!

This community 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.

1

check whether a customer name already exists

By
sneha antony
on 4/23/14, 6:57 AM 2,018 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?

1

Jagdish Panchal

--Jagdish Panchal--
2674
| 5 3 6
Gandhinagar, India
--Jagdish Panchal--

OpenERP Developer

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

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()

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

Maniganda
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
0

Omal Bastin

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

Swiming deep into openERP/ODOO

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

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

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

Odoo
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

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)

Stats

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