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

Hello all,

I have this new field defined :

partner_territory = fields.Many2one(comodel_name='res.territory', string='Partner\'s territory', required=True)


In this line, can we choose a domain for the 'required=True'? For example, could apply the 'required=True' only if self.division = True (division is an other field of the same model)?

Thanks to comment!


EDIT #1

May be the only way to manage this kind of conditionnal 'Required' for a field is in the XML of the views with this kind of code :

<field name="partner_territory" attrs="{'required':[('division','=',True)]}" />

May be we can't manage it in Python?




Awatar
Odrzuć
Autor

But is it a kind of thing we can achieve directly in the python field declaration? Is it possible?

As far as I know this is not possible.

Najlepsza odpowiedź

In my opinion the solution of the problem in XML is appropriate.

Awatar
Odrzuć
Autor

Thanks Zbik!

Najlepsza odpowiedź

Could you try: `required=lambda self: [('division', '=', True)]`

Edit: I haven't tested that though, but it's worth a try

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
2
wrz 24
1539
1
lut 19
6051
1
cze 22
13370
0
lut 21
15
1
paź 23
7708