跳至内容
菜单
此问题已终结
4 回复
79887 查看

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.

形象
丢弃
最佳答案

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)]}"

形象
丢弃
编写者

Thanks, I need to use OR.

最佳答案

  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')]}"
形象
丢弃

'&' doesn't work on odoo

最佳答案

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'))]}


形象
丢弃
最佳答案

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


形象
丢弃
相关帖文 回复 查看 活动
1
3月 25
864
1
11月 20
4445
0
10月 17
4816
1
8月 23
3173
0
11月 21
2266