Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
14924 Tampilan

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
Buang
Jawaban Terbai

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
Buang

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.

Jawaban Terbai

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
Buang
Penulis

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.

Penulis

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

for res.partner object

Where your code related res.partner

Penulis

in partner.py file.

yes in partner.py file.

Penulis

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

Penulis

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

Penulis

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.

Penulis

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

Penulis

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.

Penulis

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.

Penulis

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

Penulis

_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

Penulis

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.

Post Terkait Replies Tampilan Aktivitas
0
Jun 22
2159
0
Sep 15
3497
1
Feb 24
26
2
Feb 20
4087
4
Sep 15
5227