This question has been flagged
8 Replies
43948 Views

Hi,

I'm trying to add a custom field to a view but I gettting this error

raise ValidationError('\n'.join(errors)) ParseError: "Invalid view definition
Field `company_contact_id` does not exist
Error context :
View `view_form_sale_order_custom`
[view_id: 1316, xml_id: custom.view_form_sale_order_custom, model: sale.order, parent_id: 883]
None" while parsing custom/custom/sale_view.xml:4

The field exists in table "sale_order".


Here's my view:

<?xml version="1.0" encoding="utf-8"?>

<openerp>
    <data>
        <record id="view_form_sale_order_custom" model='ir.ui.view'>
            <field name="name">view_form_sale_order_custom</field>
            <field name="model">sale.order</field>
            <field name="priority" eval="2000" />
            <field name="inherit_id" ref="sale.view_form_sale_order" />
            <field name="arch" type="xml"> <xpath expr="//field[@name='company_id']" position="after"> <field name="company_contact_id" />
                </xpath>
            </field>
        </record>
    </data>
</openerp>


Field declaration (sale.py) :

company_contact_id = fields.Many2one('res.partner', string='Company contact', required=False, ondelete='restrict')


 __init__.py


...
import sale
...


__openerp.py

...
'depends' :['sale']
...


Any clue of what's going wrong ?


Thanks







Avatar
Discard

Are you importing the models folder too? I don't see it in your initial answer, so double checking. You import models in the __init__.py and then import sale.py from the __init__.py file which is in the models folder. Did you do that?

Author

@Yenthe sorry i'm not sure to understand what you mean by "import the model folder"

my module directory looks like this :

custom/custom

-__init__.py --> import sale

- __openerp__.py --> depends [sale]

- sale.py --> field declaration

- sale_view.xml --> view

Author

@Yenthe

here's my module (sale.py)

from openerp import models, fields, api

class sale_order(models.Model):

_inherit = 'sale.order'

company_contact_id = fields.Many2one('res.partner',

string='Contact',

required=False,

ondelete='restrict',

)

No worries - this is the same logic but just done otherwise. This looks fine. :-)

Author Best Answer

@Eli the field is created in 'sale_order'. I tried to upgrade and uninstall/reinstall the  module with

no success.


Thanks


EDIT:

I can't say why but I changed my xpath query

//field[@name='company_id'] position="after"

by

/form/group[1]/group[1]/notebook/page[2]/group[1] position="inside"


And now it's works


Thanks

Avatar
Discard
Best Answer

@o.chris The same thing happened to me. The workaround was change the xpath expression.

Avatar
Discard
Best Answer

Check if you can see company_contact_id in sales (postgresql) table, if you don't see this column, you need to restart the server and reinstall your app.

Avatar
Discard
Best Answer

You execute from command line:

>/usr/bin/odoo -d YOUR_DATABASE_NAME -u all --stop-after-init --config="/etc/odoo/odoo.conf"

and look at the erros.  In many cases, there may be some error in the language of python, in a different place than you are search it. For example, I named one of the classes

class aaa-BBB (self):


instead


class aaa_BBB (self):


and the effect was similar to yours (in addition no any log!!! and console!!! errors).



Avatar
Discard