【问题标题】:How to effectively hide field in Odoo 13 CE?如何在 Odoo 13 CE 中有效地隐藏字段?
【发布时间】:2020-08-27 05:41:38
【问题描述】:

我正在开发 Odoo 13 CE,并且我正在继承视图 l10n_latam_base.view_partner_latam_form 表单模型 res.partner 并且我无法隐藏字段 city(请注意,city 属于视图 base.view_partner_form这是我继承的视图的父视图)。我已经尝试过以下方法,但没有成功:

<field name="city" invisible="1"/>
<field name="city" position="attributes">
    <attribute name="attrs">{'invisible': True}</attribute>
</field>
<field name="city" position="attributes">
    <attribute name="invisible">1</attribute>
</field>
<xpath expr="//field[@name='city']" position="attributes">
    <!-- with this  -->
    <attribute name="invisible">1</attribute>
    <!-- and this -->
    <attribute name="attrs">{'invisible': True}</attribute>
</xpath>

我尝试使用选择器 //field[@name='city'][2]xpath,但我收到一个错误,抱怨在父视图中找不到该元素,这告诉我父视图上不超过一个 city , 我猜。另一件事是,我使用该字段作为参考来添加我自己的一些字段并且 IT'S WORKING,即这些字段显示在 city 之后,类似于:

<field name="city" position="after">
    <!-- ... -->
</field>

如果我在sn-p上面使用position="replace"city字段被替换(但我在某处读到这个不推荐),我不知道为什么这个字段如此特殊以至于不会隐藏, state_idzip 等其他字段已正确隐藏。

对此的任何帮助都非常感谢。提前致谢!

【问题讨论】:

  • 这可能是另一个使字段可见的表达式,因为使用上面的第三个代码足以使字段不可见。
  • 关于如何找到该表达式的任何想法?我已经阅读了这两种观点(父母和祖父母),我没有看到任何关于它的铃声。尽管不推荐,我暂时正在替换该字段。
  • 要检查所有继承的视图,编辑表单视图,然后查看Inherited Views 选项卡。

标签: python odoo-13


【解决方案1】:

如果你想根据条件隐藏字段,你应该使用 attrs,但如果没有条件,只需添加如下属性:

<field name="city" position="attributes">
    <attribute name="invisible">1</attribute>
</field>

注意:position="replace" 很重要,因为您从表单中删除了此字段,并且可能在此字段之前或之后还有其他字段,所以要小心。

【讨论】:

  • 感谢您的回复。这是我失败的尝试之一。
  • 请多解释
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-04-26
相关资源
最近更新 更多