Skip to Content
Menu
This question has been flagged
1 Reply
8016 Views

I'm trying to create a module for OpenERP 7 that prevents double partner records. For instance if I create a contact with the name: "Grant K."; I want an error prompt to come up when I make another contact with the exact same name, and saving is prevented.

After reading up on the web and the help section here, the best way to accomplish this seemed to use an sql constraint. In some of the topics I've read it was recommended to create a new module just for this.

I have created a module, which I named UniPa (Unique Partner); and I am able to install it on my database on the server. However, my code does not seem to be working - I can still enter double partner names without validation.

This is my first module, so I may have very well made a mistake. Can you guys see if something is missing from my code, or if I forgot something in my module?

Folder name: "UniPa" Folder contains: 3 files

**__init__.py**
import crm

**__openerp__.py**
{
    "name" : "UniPa",
    "version" : "0.1",
    "description" : """
    Adds partnet validation
    """,
    "author" : "Suresh",
    "depends" : ['crm'],
    "category" : "Generic Modules/Base",
    "init_xml" : [],
    "demo_xml" : [],
    "active": False,
    "installable": True
    }

**UniPa.py**
from osv import fields, osv

class res_partner(osv.osv): 
    _inherit = 'res.partner' 
    _sql_constraints = [ 
      ('name', 'UNIQUE (name)', 'The name of the partner must be unique !') 
    ]
res_partner()
Avatar
Discard
Best Answer

try this:

__init__.py
____________
import UniPa

I think the constraint UNIQUE on name is not pertinent because you can have two persons with the same name, Can you use a constraint like :UNIQUE (name,email) or UNIQUE (name,phone number) ? It's just a suggestion.

Avatar
Discard
Author

Thank you, Denis. I was able to set it up both ways on my test-database, validating on name and on the combination name - email. But we are a small company, and our users aren't very experienced with SAP so for now we'll just use a single validation on name. Thanks for the suggestion though!

Either way, importing my own module seemed to have done the trick. :)

Related Posts Replies Views Activity
2
Mar 15
8677
0
Jan 24
1550
1
Feb 24
26
2
Aug 23
3237
1
May 23
5313