user280960
user280960

Reputation: 721

Change Selection Field odoo 8

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

Answers (2)

@api.model
def _get_selection(self):
    #DO SOMETHING
    return choise
type = fields.Selection(selection=_get_selection, string='Type')

Upvotes: 1

Bhavya
Bhavya

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

Related Questions