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.

0

How can I enforce fields to only allow unique values?

By
David
on 7/31/14, 10:28 PM 834 views

bit of a newbie here so sorry if this question isn't good.

There are many fields in odoo that I would like to enforce unique data - eg Product Name, Category, Internal Ref etc...may other fields and modules.

Do I have to modify all the python object modules throughout odoo with SQL Contraints????  I was expecting just to check a box against a field to make it unique!

If I do have to add a python SQL constraints in python modules am I best to modify the odoo modules, or should I inherit the standard odoo object into a new object with my added constraints thereby keeping the odoo module un-modified?  eg if a standard odoo module is updated then my added constraints will still apply?

Hope this is a sensible question!

 

 

 

 

0

Ludo - Neobis

--Ludo - Neobis--
2387
| 2 2 5
Hoogvliet, Netherlands
--Ludo - Neobis--

Developer

Ludo - Neobis
On 8/1/14, 3:19 AM

Yes, you must unfortunately bring in custom code and (SQL) constraints for this. That is nearly always a given.

Due to the modular setup of Odoo the best way to modify code is as you suggested in your second statement, by using the way of inheriting models and adding/removing code in your own custom module. It is really simple to do, so you should have no trouble doing so.

Example for "old" (read: current) ORM is like so:

class my_partner(osv.osv)

    _name = "res.partner"

    _inherit = "res.partner"

    <<SQL constraint here>>

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

1 follower(s)

Stats

Asked: 7/31/14, 10:28 PM
Seen: 834 times
Last updated: 3/16/15, 8:10 AM