Skip to Content
Menu
This question has been flagged
7 Replies
9259 Views

Hi,

I am looking for a working example of inheritance in res.partner.

I just want to add one field for example after the existing field phone.

I have errors like:

Error details:
Field `my_field` does not exist 


Here after the code i have inside the .py and .xml

from openerp import models, fields

class pb_it(models.Model):

	_inherit = 'res.partner'

        my_field = fields.Char(string='My Field', size=64)


<?xml version="1.0" encoding="UTF-8"?>
<openerp>
    <data>
		<record model="ir.ui.view" id="view_res_partner_inherited">
			<field name="name">view.res.partner.inherited</field>
			<field name="model">res.partner</field>
			<field name="inherit_id" ref="base.view_partner_form" />
			<field name="arch" type="xml">
				<field name="phone" position="after">
					<field name="my_field" />
				</field>
			</field>
		</record>
</data> </openerp>

Thanks

--------------------------------------------------

Thank you Tarek Mohamed Ibrahim, at the end your answer was the correct one.

Avatar
Discard
Best Answer

This error normally happens if you changed the xml and the py file and didn't restart your server. Pls restart and try again

Avatar
Discard
Best Answer

In New API, add Import api

from openerp import models, fields, api

class pb_it(models.Model):

_inherit = 'res.partner'
my_field = fields.Char(string='My Field', size=64)

Avatar
Discard
Best Answer

Sebastian782 If u have added a new field or modified a function inside the py file. You must restart the Odoo server. And then only u need to upgrade the server Otherwise this type of error may occur.  

Avatar
Discard
Best Answer

this not resolve

Avatar
Discard

Yes works when restart the Odoo server not the odoo service. RESTART THE SERVER

Best Answer

I  had the same problem and i resolved it like this :

you have to add in your file.py :

from openerp import models,fields,api

and  precise in your init file this :

from . import file



Avatar
Discard
Author Best Answer

The error appear when i am installing the module.

Import api did not changed anything.

Restarting the server does not change anything as i get an error 500 because the module installation failled.

Here below the full error:

 ParseError: "ValidateError
Field(s) `arch` failed against a constraint: Invalid view definition

Error details:
Field `my_field` does not exist

Error context:
View `view.res.partner.inherited`
[view_id: 1072, xml_id: n/a, model: res.partner, parent_id: 126]" while parsing file:///C:/Program Files (x86)/Odoo 8.0-20150826/server/openerp/addons/toto/views/menu.xml:4, near
<record model="ir.ui.view" id="view_res_partner_inherited">
			<field name="name">view.res.partner.inherited</field>
			<field name="model">res.partner</field>
			<field name="inherit_id" ref="base.view_partner_form"/>
			<field name="arch" type="xml">
				<field name="phone" position="after">
					<field name="my_field"/>
				</field>
			</field>
		</record>
Avatar
Discard
Best Answer
class inherit_respartner(models.Model):
    _inherit = 'res.partner'
    myfield = fields.Char()


		<record model="ir.ui.view" id="add_respartner">
			<field name="name">add_respartner</field>
			<field name="model">res.partner</field>
			<field name="inherit_id" ref="base.view_partner_form" />
			<field name="arch" type="xml">
				<field name="email" position="after">
					<field name="myfield" />
				</field>
			</field>
		</record> 

I think it's the same, but it works in my module

Avatar
Discard