Odooers论坛

欢迎!

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


0

How to make a field invisible based on condition in Xml

形象
odoo
形象
丢弃
2 答案
0
形象
odoo
最佳答案

I got the answer


please update xml file like this


<field name="marital"/>
<field name="wedding_annniv" attrs="{'invisible':[('marital', '!=', 'married')]}"/>
<field name="spouse_name" attrs="{'invisible':[('marital', '!=', 'married')]}"/>
<field name="spouse_dob" attrs="{'invisible':[('marital', '!=', 'married')]}"/>
<field name="children" attrs="{'invisible':[('marital', '!=', 'married')]}"/>
形象
丢弃
0
形象
odoo
最佳答案

Hi,

Update your code like this,

<field name="marital"/>
<field name="marital_id" invisible="1"/>
<field name="wedding_annniv" attrs="{'invisible':[('marital_id', '!=', True)]}"/>
<field name="spouse_name" attrs="{'invisible':[('marital_id, '!=', True)]}"/>
<field name="spouse_dob" attrs="{'invisible':[('marital_id', '!=', True)]}"/>


In the Python,

marital = fields.Selection([
('single', 'Single'),
('married', 'Married'),
('cohabitant', 'Legal Cohabitant'),
('widower', 'Widower'),
('divorced', 'Divorced')], string='Marital Status', default='single')
marital_id = fields.Boolean(string='Status')

@api.onchange('marital')
def _marital(self):
if self.marital and self.marital == 'married':
self.marital_id = True
else:
self.marital_id = False


Thanks

2 注释
形象
丢弃
形象
odoo
-

Thanks for your answer

But i got error like this

EOL while scanning string literal

('', 1, 41, "{'invisible':[('marital_id, '!=', True)]}")

None" while parsing /opt/odoo/odoo11/addons/hr/views/hr_views.xml:34, near

<record id="view_employee_form" model="ir.ui.view">

形象
odoo
-

<field name="marital"/>

<field name="marital_id" invisible="1"/>

<field name="wedding_annniv" attrs="{'invisible':[('marital_id', '!=', True)]}"/>

<field name="spouse_name" attrs="{'invisible':[('marital_id, '!=', True)]}"/>

<field name="spouse_dob" attrs="{'invisible':[('marital_id', '!=', True)]}"/>

i changed xml file like this

I changed python file like this

@api.onchange('marital')

def _onchange_marital(self):

if self.marital and self.marital == "married" :

marital_id = True

else :

marital_id = False