Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
8076 Visualizzazioni

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
Abbandona
Risposta migliore

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
Abbandona
Autore

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

Post correlati Risposte Visualizzazioni Attività
2
mar 15
8762
0
gen 24
1657
1
feb 24
26
2
ago 23
3456
1
mag 23
5454