Reputation: 721
I am trying to generate different selection choices depending on other field in the Model. I am working in Odoo 8. Below is the code :
My Model: (test.py)
type = fields.Selection(selection='_get_selection', string='Type')
@api.onchange('role_name')
def _get_selection(self):
choise = []
if self.role_name == 'primary':
choise.append(('unit','Unit Case'))
if self.role_name == 'reserve':
choise.append(('res','Reserve Case'))
return choise
The View: (template.xml)
<field name="type" widget="selection"/>
But i don't see any values in Selection Field.
Please Help.
Thanks,
Upvotes: 1
Views: 2642
Reputation: 156
@api.model
def _get_selection(self):
#DO SOMETHING
return choise
type = fields.Selection(selection=_get_selection, string='Type')
Upvotes: 1
Reputation: 488
This is an example from 'account.invoice' in Odoo 8:
@api.model
def _get_reference_type(self):
return [('none', _('Free Reference'))]
reference_type = fields.Selection('_get_reference_type', string='Payment Reference',
required=True, readonly=True, states={'draft': [('readonly', False)]},
default='none')
This should help you in resolving the issue.
Upvotes: 1