Odoo 中如何在一个 form 中有条件的显示 field
Odoo 开发中经常会遇到这样的需求,对象中根据条件是否显示一个字段。比如如果不是创建人,不不显示客户的联系方式,Odoo 中如何实现呢。
<一>domain
在 odoo 中可以根据对象字段的值或者关系确定是否显示一个字段。
例1)
结婚了才公布男朋友的名字。
2)
这是动态 domain 的例子,根据选择结构确定字段是否显示。
还有一种方式是,可以在 view 中,根据 states 的值确定字段是否显示。
<二>view 的state
<三>动态视图
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
if context is None:context = {}
res = super(rhwl_gene, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar,submenu=False)
if res['type']=="form":
id = res['id']
//根据id去取得资料,并进行判断
if 条件成立:
doc = etree.XML(res['arch'])
doc.xpath("//form")[0].set("edit","false")
res['arch']=etree.tostring(doc)
return res
本文来源:https://www.2haoxitong.net/k/doc/8e217101b14e852459fb57cd.html
文档为doc格式