Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
1 Antworten
4896 Ansichten

Good morning, I'd like to know if is possible change the options in a selection field depending of another field.

For example, I have a selection field with [('option1', 'Option 1'),('option2', 'Option 2')]

And I have a boolean field with a compute with @api.depends function.

I'd like to know if that boolean is checked, if I can add a option to my selection field, for example, add ('option3', 'Option 3').


Thank you so much for your answers!

Avatar
Verwerfen
Beste Antwort
For that you can write code similar to this
field_one = fields.Selection([('option1', 'Option 1'), ('option2', 'Option 2')], string='Field One')
field_two = fields.Selection([], string='Field Two', compute='_compute_field_two', store=True, depends='field_one')
 
@api.depends('field_one')
def _compute_field_two(self):
if self.field_one == 'option1':
self.field_two = [('option3', 'Option 3'), ('option4', 'Option 4')]
else:
self.field_two = [('option5', 'Option 5'), ('option6', 'Option 6')]

Avatar
Verwerfen
Verknüpfte Beiträge Antworten Ansichten Aktivität
1
Sept. 22
3996
3
Aug. 22
2672
2
Juni 22
3564
3
Aug. 24
5337
4
Juli 23
6899