Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
7 Odpowiedzi
9800 Widoki

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.

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Najlepsza odpowiedź

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)

Awatar
Odrzuć
Najlepsza odpowiedź

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.  

Awatar
Odrzuć
Najlepsza odpowiedź

this not resolve

Awatar
Odrzuć

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

Najlepsza odpowiedź

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



Awatar
Odrzuć
Autor Najlepsza odpowiedź

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>
Awatar
Odrzuć
Najlepsza odpowiedź
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

Awatar
Odrzuć