继承时字段不存在报错account.invoice

Field does not exist error when inheriting account.invoice

使用 Odoo 10(取自 GitHub commit 7413b26, branch 10.0), installing a module which I'm porting over from Odoo 8 fails due to not finding a field in an inherited account.invoice. Problem is, this field is created within the inherited model, and the problem persists down to the point of being able to create a MCVE 以说明行为:

invoice.py:

from odoo import fields, models
class AccountInvoice(models.Model):
    _inherit = 'account.invoice'
    a = fields.Char()

invoice.xml:

<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <record model="ir.ui.view" id="account_invoice_form_view">
            <field name="name">account.invoice.form</field>
            <field name="model">account.invoice</field>
            <field name="type">form</field>
            <field name="inherit_id" ref="account.invoice_form"/>
            <field name="arch" type="xml">
                <field name="origin" position="after" >
                    <field name="a" />
                </field>
            </field>
        </record>
    </data>
</openerp>

__manifest__.py{'name':'Invoice bug','depends':['account'],'data':['invoice.xml'],'installable':True}__init__.py 就是通常的 import invoice

这样的代码失败了

ParseError: "Error while validating constraint
Field `a` does not exist
Error context:
View `account.invoice.form`
[view_id: 554, xml_id: invoice_bug.account_invoice_form_view, model: account.invoice, parent_id: 421]
None" while parsing /odoo/addons/invoice_bug/invoice.xml:4, near
[XML follows]

这里还有一些观察结果:

是我的代码有误,还是有解决方法?

一切都很好,应该将字段添加到您的模型中。 对你的问题的一种解释是 odoo 没有到达你的代码。

您的项目中是否只有一个初始化文件,或者您正在使用多文件夹项目。检查你的缩进。

尝试更改标签

<openerp>..</openerp> to <odoo>..</odoo>

origin 字段在 account.invoiceaccount.invoice.line[= 中可用36=]型号。

如果您在表单视图中签入 invoice_form 那么我们将获得 2 倍的原始字段。

  1. invoice_line_ids 内联树视图。

  2. 其他信息页面。

如果我们在之后写入字段位置,那么系统将在 invoice_line_ids 内联树视图中找到第一个字段,由于这个原因我们会出错。

但是 Odoo 给出了错误的错误信息。

你需要按照下面的xpath。

<xpath expr="//page[@name='other_info']/group/group[2]/field[@name='origin']" position="after">
    <field name="a"/>               
</xpath>

这可能对你有帮助。