Help

欢迎!

该社区面向专业人士和我们产品和服务的爱好者。
分享和讨论最好的内容和新的营销理念,建立您的专业形象,一起成为更好的营销人员。


0

how to set conditions for 'res.contry' in odoo 15

Avatar
odoo
Avatar
Discard
2 Answers
0
Avatar
odoo
Best Answer

Hi ,
Try to add the domain in the destination location like:

 < field name="source_location"/ >
< field name="destination_location" domain="[('id', '!=', source_location)]"/ >


Please vote the answer if it work.

Avatar
Discard
0
Avatar
odoo
Best Answer
** Assuming this two fields have Many2one connection with res.country **
from odoo import models, api


class YourClass(models.Model):
_inherit = 'module.model'

@api.onchange('source_location')
def set_domain_destination_location(self):
for rec in self:
domain = {'destination_location': [('id', '!=', rec.source_location.id)]}
return {'domain': domain}


4 Comments
Avatar
Discard
Avatar
odoo
-

Hi Arian Shariat,
The domain will only active if you change or select the source location. Otherwise the domain will inactive and you can select any value in the destination location. So the best way is the domain on a field instead of onchange.

Avatar
odoo
-

@Malay Hi Malay
You are right. In my approach, the source_location value should be chosen first and then the domain for destination_location domain will be applied. But I can't find any contradiction between this approach and what the question is.

Avatar
odoo
-

Hi Arian Shariat,
He can able to select same country value if he select the same destination country first.

Yes he can use on change if he wants to omit this scenario. But the best way is still the domain on a field.

Avatar
odoo
-

You are right about that Malay. I'll change my answer based on it. Thanks