تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
5294 أدوات العرض
Hello, I need to know how I could define a domain according to the value of another field in the form


or these are the two domains you would need to activate one or the other depending on the value of another field x_availability


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

You can follow this: https://youtu.be/XGqXEL2qQmE

Hope it helps,

Thanks

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

Unfortunately return domain has been deprecated.

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

In odoo 17 , how it work brother ?

أفضل إجابة

Hi Danny,

To define a field domain (field_1) according to the value of another field (field_2), you have to create onchange('field_1') function based on field_1 to return domain of field_2. 

Check the exemple below:
 
@api.onchange('(field_1')
def onchange_field_1(self):
domain = [('id', '=', 0)]
if self.field_1:
domain = expression.OR([domain, [('id', '=', self.field_1.some_field)]])
return {'domain': {'field_2': domain}}



 

Best regards,


Imal-Tech    



الصورة الرمزية
إهمال
الكاتب

I know, but I mean that if for example field 1 = True then the domain of field 2 = domain 1
else
field 1 = False then the domain of field 2 = domain 2, I don't know if you understand me

Check this :

@api.onchange('(field_1')
def onchange_field_1(self):
if self.field_1 == True:
domain = your_domain_1_her
else:
domain = your_domain_2_her
return {'domain': {'field_2': domain}}

الكاتب

Thus, I would be left with the real fields and domains that I would like to use. I must clarify that the x_tinconf field is of the selection type. When declaring it, it gives an error, could you correct me?

@api.onchange('(x_tinconf')
def onchange_x_tinconf(self):
if self.x_tinconf == 'Pvv':
domain = [('x_pvv', '=', True)]
else:
if self.x_tinconf == 'Hsh':
domain = [('x_hsh', '=', True)]
return {'domain': {'x_inconf': domain}}

Danny, could you share with us the error?

المنشورات ذات الصلة الردود أدوات العرض النشاط
2
مايو 24
3322
4
نوفمبر 23
2056
2
ديسمبر 21
5464
1
مايو 21
3348
Many2many fields تم الحل
2
مارس 23
3010