This question has been flagged
1 Reply
4379 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?

Avatar
Discard
Best Answer

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

Avatar
Discard
Author

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.

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.