Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
2 Odpowiedzi
2698 Widoki

i have 2 fields in my model source_location and destination_location

if i choose a country in source_location and i want to set  that country not visible in destination_location 

these 2 are many2one fields

Awatar
Odrzuć
Najlepsza odpowiedź

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.

Awatar
Odrzuć
Najlepsza odpowiedź
** 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}


Awatar
Odrzuć

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.

@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.

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.

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

Powiązane posty Odpowiedzi Widoki Czynność
2
sie 25
2457
3
lut 25
3788
0
maj 24
46
1
kwi 24
3504
4
wrz 23
5036