【问题标题】:how to change a field requirement in xml?如何更改xml中的字段要求?
【发布时间】:2016-05-20 12:04:47
【问题描述】:

我有一个字段“必需”=True,我想在继承的形式中将其更改为 False。

      <field name="customer_id" position="replace">
               <attribute name="required">False</attribute>
      </field>

但我得到了:

      Integrity Error
The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: customer_id - customer.id]

【问题讨论】:

  • 检查 customer_id 的 python 文件,如果它被标记为 required=True 则 False 不起作用

标签: xml views odoo-8


【解决方案1】:

在 ODOO 中,如果在 python 文件中将字段设置为 required=True 不能将其标记为 required=xml 文件中的Flase。

为了使它成为非必需

在 python 文件中重新声明字段,required=False。 因为一旦在 python 中声明了一个字段required=True,它也设置为在数据库中是必需的,但对于 xml,情况并非如此。

希望对您的情况有所帮助。

【讨论】:

  • 是的。到底。那就是我所做的。我重新声明了 python 字段。谢谢
【解决方案2】:
In xml file you can do  it: 
<field name="customer_id" position="attribute">
   <attribute name="required">False</attribute>
</field>

and in python code it is also possible to make required false.
If you want field required False in view add required=False in xml.
if you want field required False which is required True in parent (in database constrains) simply override it in inherited class.

【讨论】:

  • 是 position="attributes" 不是 "attribute",谢谢
猜你喜欢
  • 2020-03-29
  • 1970-01-01
  • 2015-12-27
  • 1970-01-01
  • 1970-01-01
  • 2019-04-04
  • 2016-01-30
  • 2018-08-31
  • 1970-01-01
相关资源
最近更新 更多