Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
8 Răspunsuri
47586 Vizualizări

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







Imagine profil
Abandonează

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?

Autor

@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

Autor

@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. :-)

Autor Cel mai bun răspuns

@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

Imagine profil
Abandonează
Cel mai bun răspuns

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

Imagine profil
Abandonează
Cel mai bun răspuns

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.

Imagine profil
Abandonează
Cel mai bun răspuns

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).



Imagine profil
Abandonează
Related Posts Răspunsuri Vizualizări Activitate
1
mar. 23
6269
2
ian. 19
3836
7
oct. 18
10132
2
mar. 15
9977
5
dec. 23
19040