تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
1789 أدوات العرض

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 ?

الصورة الرمزية
إهمال
أفضل إجابة

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

الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thank you !!

This works !

BUT !!


It's deprecated

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

الصورة الرمزية
إهمال

You can use dynamic domain methods

المنشورات ذات الصلة الردود أدوات العرض النشاط
1
أكتوبر 23
1540
2
أغسطس 23
3641
4
أغسطس 23
19958
3
أكتوبر 22
10477
3
مارس 22
36863