Reputation: 824
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:
product.template
and view product.product_template_only_form_view
(with <field name="default_code" position="after">
, works properly<xpath expr="//field[@name='origin']" position="after">
instead of a field position="after"
does not affect the errorsale
module, succeeds in extending account.invoice
and the same view (account.invoice_form
) properly: sale/models/account_invoice.py:8, sale/views/sale_views.xml:653period_id
with date
)Is my code wrong, or is there a workaround ?
Upvotes: 2
Views: 2278
Reputation: 14746
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.
invoice_line_ids in-line tree view.
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
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