跳至内容
菜单
此问题已终结
8 回复
47385 查看

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







形象
丢弃

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?

编写者

@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

编写者

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

编写者 最佳答案

@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

形象
丢弃
最佳答案

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

形象
丢弃
最佳答案

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.

形象
丢弃
最佳答案

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



形象
丢弃
相关帖文 回复 查看 活动
1
3月 23
6135
2
1月 19
3710
7
10月 18
9931
2
3月 15
9883
5
12月 23
18943