跳至內容
選單
此問題已被標幟
7 回覆
9807 瀏覽次數

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.

頭像
捨棄
最佳答案

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

頭像
捨棄
最佳答案

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)

頭像
捨棄
最佳答案

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.  

頭像
捨棄
最佳答案

this not resolve

頭像
捨棄

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

最佳答案

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



頭像
捨棄
作者 最佳答案

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>
頭像
捨棄
最佳答案
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

頭像
捨棄