Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
2 Răspunsuri
2078 Vizualizări

I have an on_change method that assigns a list of tuples to a Selection field


But I get the error message in the subject

Why is that ?

The tuples are like (int, string)


I tried casting the 2 elements in the tuples to 2 strings, int for the id and string for the value, string for the id and int for the value...


I just want to create a list of choices for a dropdown menu field that depends on the value in another field


How am I supposed to do that ?

Imagine profil
Abandonează
Cel mai bun răspuns

Hi Adriano,

Try this code 

@api.onchange('selection_field')
def _onchange_domain(self):
if self.selection_field == 'value':
domain = [('id', '=', self.id)]
else:
domain = []
return {'domain': {'another_field': domain}}

Also, Check this reference to apply dynamic domain for relational fields 

Dynamic domain


Regards

Imagine profil
Abandonează
Autor Cel mai bun răspuns

Thank you !!

This works !

BUT !!


It's deprecated

i read here an answer about how to properly do this but I don't understand

Imagine profil
Abandonează

You can use dynamic domain methods

Related Posts Răspunsuri Vizualizări Activitate
1
oct. 23
1854
2
aug. 23
4062
4
aug. 23
20351
3
oct. 22
10834
3
mar. 22
37211