I have this code for the resignation module I am working on. I need some specific options in the dropdown menu to be visible only to the female employees and the male employees cannot see them. This is for odoo v17.
But with this code, the reasons are not visible in the form view, it is just showing blank. Please help me with this.
reasons = fields.Selection(selection="_get_reasons", string='Reason', required=True)
@api.onchange('gender')
def _onchange_gender(self):
# Update the resignation reasons based on the selected gender
return {'domain': {'reasons': [('gender', '=', self.gender)]}}
@api.model
def _get_reasons(self):
# Define resignation reasons based on the selected gender
options = []
if self.gender == 'male':
options = [('reason1', 'Reason 1'),
('reason2', 'Reason 2'),
('reason4', "Reason 4"),
('reason5', 'Reason 5'),
('reason6', 'Reason 6'),
('reason7', 'Reason 7'),
('reason8', 'Reason 8')]
elif self.gender == 'female':
options = [('reason1', 'Reason 1'),
('reason2', 'Reason 2'),
('reason3', 'Reason 3'),
('reason4', "Reason 4"),
('reason5', 'Reason 5'),
('reason6', 'Reason 6'),
('reason7', 'Reason 7'),
('reason8', 'Reason 8')]
return options