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