Odoo Help


where does odoo store the selection field string?

willie ho
on 9/29/15, 9:48 PM 2,616 views

i need to get the relation of odoo selection field value and string.

which table is storing the data?


Axel Mendoza

--Axel Mendoza--
| 7 8 8
Camaguey, Cuba
--Axel Mendoza--

DevOps - Full stack - Software Architect - Developer - Technology Integrator

I could help you to develop anything and solve complex problems based on technologies, integrations and tricky stuffs mostly in Python with OpenERP/Odoo, Zato, Django and many others frameworks programming languages and technologies.

I offers consulting services to anyone with an unanswered questions or needs for customizations. Think about it, maybe it's better to have an expert to solve your issues and projects than having a full-time employee trying to understand what to do and how

Reach me at aekroft@gmail.com

Axel Mendoza
On 9/30/15, 12:23 AM

Normally It does not store the values in the database. They are defined in python and you could access to those values in the model like:

Marvin Taboada
On 9/30/15, 1:30 AM

Hello willie ho,

The value was supposed to be stored in the 'selection' field of the 'ir_model_fields' table (by using the create and write methods of 'ir.model.fields'), but records in that table are actually inserted by direct SQL statements during module installation and the 'selection' column is omitted there, see here: https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L357

You can run the following SQL queries to verify that the selection column is not populated:

-- 'ir.model.fields' has some selection fields, not stored in the DB 
SELECT id, model, ttype, name, field_description, selection
FROM ir_model_fields
WHERE model like 'ir.model.fields'
ORDER BY name;
-- selection is either NULL or empty for all fields in the DB
SELECT id, model, ttype, name, field_description, selection, domain
FROM ir_model_fields
AND selection NOT LIKE ''
ORDER BY name;

Anyway, you can directly get the 'selection', and also some other field attributes, by directly introspecting the field object, please see the following example

model_name = 'ir.model.fields' 
selection_field = 'on_delete'
model_obj = self.pool[model_name]
field_selection = model_obj._columns[selection_field].selection

In the above example I'm obtaining the 'selection' value for the following field: https://github.com/odoo/odoo/blob/8.0/openerp/addons/base/ir/ir_model.py#L267

Not storing the 'selection' values in the database is related to the fact that you can either assign a list, a method reference or even a method name (new since Odoo 8.0) for selection field values. At runtime, the value is appropriately evaluated depending on its type: https://github.com/odoo/odoo/blob/8.0/openerp/fields.py#L1363

See this link for a reference: https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.fields.Selection


About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 9/29/15, 9:48 PM
Seen: 2616 times
Last updated: 9/30/15, 1:30 AM