Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
79988 Lượt xem

Hello, how I can define multiple conditions in attrs of a field? I need hide field_name_3 when field_name_1 AND field_name_2 are empty. I'm trying to use following condition:

<field name="field_name_3" attrs="{'invisible':[('filed_name_1','=',False),('fieled_name_2','=',False)]}"/>

But it works like the OR.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

I think with this syntax it works like AND condition behaviour.

If you want to specify OR condition you must use this syntax :

attrs="{'invisible':['|',('filed_name_1','=',False),('fieled_name_2','=',False)]}"

Ảnh đại diện
Huỷ bỏ
Tác giả

Thanks, I need to use OR.

Câu trả lời hay nhất

  attrs="{'invisible':['|',('filed_name_1','=',False),('fieled_name_2','=',False)]}"   for OR

  attrs="{'invisible':['&',('filed_name_1','=',False),('fieled_name_2','=',False)]}"  for AND

<field name="name" attrs="{'invisible': [('condition1', '=', False)], 'required': [('condition2', '=', True)]}"/><!-- as default it works as AND without any additional '|' or '&'-->

You can use more than two conditions, then you should use '|','|','&' depending on conditions order and what you want to achieve.
for example attrs="{'invisible': [('product_lines_id','!=','Computer'),('product_lines_id','!=','Server')],'required':[
'|',('product_lines_id','=','Computer'),('product_lines_id','=','Server')]}"
Ảnh đại diện
Huỷ bỏ

'&' doesn't work on odoo

Câu trả lời hay nhất

For Odoo 14:
You can use "in" or "not in" operator for multiple values, for attrs you can write as following :

"attrs"="{'invisible':[('field','not in',(values))]}"

Ej.
attrs="{'invisible':[('name','not in',('Bank','Cheque'))]}


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

You need to use escape character of  '&' in order to get the AND condition work. Similar is the case of  '>' and  '


Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 3 25
947
1
thg 11 20
4503
0
thg 10 17
4869
1
thg 8 23
3254
0
thg 11 21
2348