Help

0

How can I prevent users from entering duplicate Vendors? Based on NAME only

Accounting users are not searching first for a Vendor when the enter a Bill.

Avatar
Discard
3 Answers
0
Avatar
Ray Carnes
Best Answer

You can setup an Automated Action that searches for records based on any combination of name, email, phone, etc.

This example is just for name:


This is the code snippet:

exists = env['res.partner'].search([('name','=',record.name),('supplier','=',True),('id','!=',record.id)])
if exists:
raise Warning('Vendor "' + record.name + '" is already in Odoo!')

This is the message this action will show users if they enter a Vendor already in Odoo:


3 Comments
Avatar
Discard
Avatar
Ermin Trevisan
-

I did not think of using automated action for this, that's cool!

Avatar
Thomas Guénard
-

I got this error while implementing this automated action (using V8)

ValueError: "name 'record_name' is not defined" while evaluating.

Avatar
Ray Carnes
-

Sorry, I don't work with Odoo 8 any longer.

0
Best Answer

Hi,

You can override the create method or add a constrains for the model.

If you are overriding the create method you can check whether there is a vendor already exits in the db with the same name.

By giving constrains for the model res.partner

@api.constrains('name')
def _check_name(self):
partner_rec = self.env['res.partner'].search(
[('name', '=', self.name), ('supplier', '=', True), ('id', '!=', self.id)])
if partner_rec:
raise ValueError(_('Exists ! Already a vendor exists in this name'))


Also, you can check the usage of the SQL constrains,

_sql_constraints = [
('name', 'unique (name)', 'The name already Exists!'),
]


Thanks


Avatar
Discard
0
Avatar
Jacobus Erasmus
Best Answer

It depends on your specific situation but in most cases, my suggestion is to simply set up your users so that they cannot add vendors and only a certain set of users (Accountant or Purchasing) manager can add a vendor. In most cases to create a new vendor is an involved process with contracts etc that need to be negotiated so a normal salesperson or even a purchasing clerk should not have access to add vendors. 


3 Comments
Avatar
Discard
Avatar
Ray Carnes
-

Agreed - you make a great point. This is certainly something I would recommend.

Avatar
Ermin Trevisan
-

Now we have 3 typical answers, I know it is oversimplified, but somehow I see a typical american, indian and european (even when Jacobus shows the south-african flag) answer here :-)

Avatar
Ray Carnes
-

I'm Australian, I just happen to live in the USA!