Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
7 Trả lời
9804 Lượt xem

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.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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)

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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.  

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

this not resolve

Ảnh đại diện
Huỷ bỏ

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

Câu trả lời hay nhất

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



Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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>
Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất
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

Ảnh đại diện
Huỷ bỏ