如何从odoo中的`account.invoice`模型中删除必填字段`account_id`
How to remove required field `account_id` from a `account.invoice`model in odoo
我尝试将其从文件中删除 account-> models-> account_invoice.py
。
但它显示错误。那么,有没有其他方法可以将其从 python 文件中删除。如何在 odoo 中自定义预定义模型?
您不能删除字段。您可以删除所需的 属性,但不能删除字段本身。
为此,您必须继承 account.invoice
模型并重新定义该字段。
喜欢:
class AccountInherit(models.Model):
_inherit = 'account.invoice'
< here define that field, it must be the same as the original but the required property >
绝对同意 Michele Zacceddu 的正确答案,您应该在其中覆盖模型,并更新该字段的属性,例如 required
或 readonly
,尤其是对于重要字段,例如 account_id
.
但是,如果碰巧在您绝对需要的情况下,您确实可以选择将所有字段一起删除。您需要确保处理删除 xml 视图和 python 方法中对您要删除的字段的所有引用。
<record>
...
<field name="arch" type="xml">
<field name="account_id" position="replace"/>
</field>
</record>
class Invoice(models.Model):
_inherit = 'account.invoice'
def _method(self):
# override methods that reference or use the fields we
# are about to delete so that we don't break core
delattr(odoo.addons.account.models.account_invoice.AccountInvoice, 'account_id')
我尝试将其从文件中删除 account-> models-> account_invoice.py
。
但它显示错误。那么,有没有其他方法可以将其从 python 文件中删除。如何在 odoo 中自定义预定义模型?
您不能删除字段。您可以删除所需的 属性,但不能删除字段本身。
为此,您必须继承 account.invoice
模型并重新定义该字段。
喜欢:
class AccountInherit(models.Model):
_inherit = 'account.invoice'
< here define that field, it must be the same as the original but the required property >
绝对同意 Michele Zacceddu 的正确答案,您应该在其中覆盖模型,并更新该字段的属性,例如 required
或 readonly
,尤其是对于重要字段,例如 account_id
.
但是,如果碰巧在您绝对需要的情况下,您确实可以选择将所有字段一起删除。您需要确保处理删除 xml 视图和 python 方法中对您要删除的字段的所有引用。
<record>
...
<field name="arch" type="xml">
<field name="account_id" position="replace"/>
</field>
</record>
class Invoice(models.Model):
_inherit = 'account.invoice'
def _method(self):
# override methods that reference or use the fields we
# are about to delete so that we don't break core
delattr(odoo.addons.account.models.account_invoice.AccountInvoice, 'account_id')