ElementW
ElementW

Reputation: 824

Field does not exist error when inheriting account.invoice

Using Odoo 10 (fetched from 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 to illustrate the behavior:

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>

The __manifest__.py is {'name':'Invoice bug','depends':['account'],'data':['invoice.xml'],'installable':True} and __init__.py is just the usual import invoice.

Such code fails with a

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]

Here are some more observations:

Is my code wrong, or is there a workaround ?

Upvotes: 2

Views: 2278

Answers (3)

origin field is available in account.invoice and account.invoice.line model.

If you check in form view invoice_form then we are getting 2 times origin fields.

  1. invoice_line_ids in-line tree view.

  2. Other info page.

If we write field position after then system will find first field inside invoice_line_ids in-line tree view, due to that reason we are getting error.

But Odoo is giving wrong error message.

You need to follow below xpath.

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

This may help you.

Upvotes: 2

sfx
sfx

Reputation: 1841

Try changing the tags

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

Upvotes: 0

Charif DZ
Charif DZ

Reputation: 14721

Every thing is good the field should be added to your model. The one explanation for your problem is odoo didn't reach your code.

Do you have only one init file in your project or you are using multi folder project. Check your indentation.

Upvotes: 0

Related Questions