Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
There are 3 ways to provide selection list values that is accepted by OpenERP:
- Specifying directly in the field.selection definition: 'field_1': fields.selection([('value1', 'String 1'), ('value2', 'String 2')], 'Field Label')
- Specifying using a name list variable outside of the field.selection definition: 'field_1': fields.selection(LIST_VARIABLE, 'Field Label'). Where LIST_VARIABLE is defined beforehand: LIST_VARIABLE = [('value1', 'String 1'), ('value2', 'String 2')]
- Specifying using a method: 'field_1': fields.selection(_method_name, 'Field Label'). Where _method_name is defined beforehand:
def _method_name(self, cr, uid, context=None):
return [('value1', 'String 1'), ('value2', 'String 2')]
Now, you need to check first which one is your current selection field is. If it is using method No. 1, then you need to redefine it to use either method No 2 or method No 3. If it is using method No. 2 or 3, you just need to change either the variable (you can use LIST_VARIABLE.append(('value3', 'String 3'))) to return the new value.
Selection field allows static value in list of tuples
registration_state = fields.Selection([('select_1', 'One'), ('select_2', 'Two'), ('select_3', 'Three')], 'Select')
in that you can not add values.
so the solutions is to add a many2one field, which allows you to add value in it. for that you need to define a new model of your selection.
_name = 'selection.selection'
name = fields.Char('Name', required=True)
value = fields.Char('Value', required=True)
now in your class you need to add many2one field which is referencing to your selection model like,
_name = 'your.model'
my_selection = fields.Many2one(selection.selection, Selections)
now in xml file while defining the fields you need to add a widget to your selection field like,
<field name="my_selection" widget="selection" />
to configure the selections you can make menu under configuration as per your need.
hope this helps.
There are two kinds of "selection" fields, so there are two ways that the values are managed.
The one that is defined as "fields.selection(...)" [defined in the .py file, the model] has values defined there in a comma seperated list. In this case you add the new value to the list in the .py file.
Or a field can be defined as a one to many2one(...), in which case the line that defines it in the .py file will indicate what table has the values. Usually use can add new values from the interface on this type of field.
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.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 1/12/15, 11:43 AM|
|Seen: 11182 times|
|Last updated: 1/24/17, 9:34 AM|