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 allowed selection field values?

By
Timo Talvitie
on 9/2/14, 3:46 AM 881 views

I'd like to know how Odoo keeps track of allowed dropdown values (for example, values for the priority field in project.task). Is it possible to view and add them dynamically via ORM or a regular SQL query?

0
Javier Matos Odut
On 9/2/14, 4:03 AM

Hello Timo,

For that I use to create a many2one field in the model pointing to a new model whose instances are the values that I want to allow.

Let's say that you have a partner and you want to add a select input whose values can be dinamically generated. Then you can create the following field into the res.partner:

'x_partner_type_id': fields.many2one(
    'mycompany.customer.type',
    'Partner Type',
    required=True,
    ondelete='restrict',
),

Then, you will have to create the model mycompany.customer.type where you will have all the choices:

from openerp.osv import fields, osv

class customer_type(osv.Model):
    _name = 'mycompany.customer.type'
    _columns = {
        'name': fields.char('Name', size=64, required=True),
        'description': fields.text('Description'),
    }

customer_type()

And that's it. Now you have a field in your partner whose values are generated dinamically by using your view (you have to add x_partner_type_id into partner's view).

Thanks Javier, but the fields already exist in Odoo's core as selection lists. Converting them to many2ones may be an option, but before attempting that I'd like to try if reading/adding list values programmatically works. In the project_task postgres table 'priority' is a regular varchar column, so Odoo keeps track of the allowed values somewhere else, but I haven't figured out where.

Vizucom Oy, Timo Talvitie
on 9/2/14, 4:50 AM

You can try to redefine the field that you want to change to allow additional values (take base values, and add additional ones). I think that choices for a select field are hardcoded into .py files, and Odoo does not use db for those values.

Javier Matos Odut
on 9/2/14, 4:59 AM

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/2/14, 3:46 AM
Seen: 881 times
Last updated: 3/16/15, 8:10 AM