This question has been flagged
2 Replies
6546 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!

 

 

 

 

Avatar
Discard
Best Answer

An example to use check whether data is unique in a field.


    _sql_constraints = [

        ('field_name', 'unique (field_name)', 'The field  must be unique  !')

    ]

Avatar
Discard
Best Answer

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

Avatar
Discard