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

where does odoo store the selection field string?

By
willie ho
on 9/29/15, 9:48 PM 1,463 views

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

which table is storing the data?

1

Axel Mendoza

--Axel Mendoza--
10205
| 7 7 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 an 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:

self.env['model_name']._fields[field_name].selection
0
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
WHERE selection IS NOT NULL
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

Regards.

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: 9/29/15, 9:48 PM
Seen: 1463 times
Last updated: 9/30/15, 1:30 AM