I am using Odoo 12, and trying to display to selection-fields, in formView,
first selection field has 2 values, but second selection field has 4 values, 2 for each choosen field from first-selection-field.
I am giving dummy-code, as I can't show production-code.
mainfile.py
contents areclass MainClassFile(models.Model):
first_field = fields.Selection([ ('first':'Item-1'), ('second':'Item-2')],string="first-Selection") second_field = fields.Selection([('1','one') ,('2','two') ,('3','three') ,('4','four')], string='Only-two-fields') @api.onchange('first_field') def show_two_fields_only(self): if self.first_field == 'first': return {'domain':{second_field = fields.Selection([('1','one') ,('2','two')] else return {'domain':{second_field = fields.Selection([('3','three') ,('4','four')]
xml file for same py-file having form-view as:
<group name="default" col="4" colspan="2">
<field name="first_field" required="1" default_focus="1" onchange="show_two_fields_only('first_type'/>
<field name="second_field" required="1"/>
</group>
how can I domain filter second_field, based on value choosen from first_field,
eg. if first_value choosen is 'first' then form should show only second_field values as (1,2),
if first_value choosen is 'second' then form should show only second_field values as (3,4),
as dropdown selection list?