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.

3

Partner validation: no double names allowed

By
Rebel
on 5/21/13, 11:26 AM 2,179 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()
3

Bonnet Denis

--Bonnet Denis--
925
| 5 6 8
Vannes, France
--Bonnet Denis--

Engeneer at MGS Consulting Ouest at Vannes, FRANCE

Bonnet Denis
On 5/21/13, 11:42 AM

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.

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. :)

Rebel
on 5/21/13, 1:42 PM

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: 5/21/13, 11:26 AM
Seen: 2179 times
Last updated: 6/11/15, 4:57 PM