![](/img/trans.png)
[英]How to link custom python function to the create button of form view in odoo
[英]Call python function in xml for set attribute of form view in odoo 13
我有一个表单视图,我想动态设置它的创建和编辑属性。 这是我的表单视图记录:
<record model="ir.ui.view" id="estate_property_type_form">
<field name="name">estate_property_type_form</field>
<field name="model">estate.property.type</field>
<field name="arch" type="xml">
<form>
<sheet>
some fileds...
</sheet>
</form>
</field>
</record>
我使用 xpath 标记在那里设置创建和编辑属性,但我不能在 Estate.property.type model 中调用我的 function
<record id="changing_attrs" model="ir.ui.view">
<field name="name">changing attrs</field>
<field name="model">estate.property.type</field>
<field name="inherit_id" ref="estate_property_type_form"/>
<field name="arch" type="xml">
<xpath expr="//form" position="attributes">
<attribute name="create">model_estate_property_type_form.test()</attribute>
</xpath>
</field>
</record>
在测试 function 中,我做了一些逻辑并返回真或假。 我还在属性标签之间尝试了 user.env['estate.property.type'].test()、estate.property.type.test() 和 test(),但它没有用。 有人可以帮我在这里打电话给我的 function 或者告诉我另一种动态设置表单属性的方法??????
您可以使用fields_view_get
方法。 正确替换YourClass
和your_text()
,
@api.model
def fields_view_get(self, view_id=None, view_type='form', toolbar=False, submenu=False):
res = super(YourClass, self).fields_view_get(
view_id=view_id, view_type=view_type, toolbar=toolbar, submenu=submenu
)
doc = etree.XML(res['arch'])
if view_type == 'form' and self.your_test():
for node in doc.xpath('//{}'.format(view_type)):
node.set('create', '0')
res['arch'] = etree.tostring(doc, encoding='unicode')
return res
我希望这个答案可以对你有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.