Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
3 Відповіді
11755 Переглядів

Hello. I am trying to inherit res.partner into a new model, adding a field as suggested in "Creating a model" tutorial. I suppose that a line from the code must be changed to make it work, avoiding the "instructor field does no exist" error: 

instructor = fields.Boolean("Instructor", default=False) 

must be changed for 

_column = {'instructor': fields.Boolean("Instructor", default=False)}

according with a help forum in Odoo. The code for partner.py which does not provoke errors is this:

# -*- coding: utf-8 -*-
from openerp import models, fields, api
class Partner(models.Model):
_inherit = 'res.partner'
# Add a new column to the res.partner model, by default partners are not
# instructors
# instructor = fields.Boolean("Instructor", default=False)
_column = {'instructor': fields.Boolean("Instructor", default=False)}
session_ids = fields.Many2many('openacademy.session',
string="Sesiones Atendidas", readonly=True)

However, when enabling partner.xml to module the error appears again:

ParseError: "Invalid view definition
Error details:
Field `instructor` does not exist
Error context:
View `partner.instructor`

It's code is next:

<?xml version="1.0" encoding="UTF-8"?>
<openerp>
<data>
<!-- Add instructor field to existing view -->
<record model="ir.ui.view" id="partner_instructor_form_view">
<field name="name">partner.instructor</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<notebook position="inside">
<page string="Sesiones">
<group>
<field name="instructor"/>
<field name="session_ids"/>
</group>
</page>
</notebook>
</field>
</record>
<record model="ir.actions.act_window" id="contact_list_action">
<field name="name">Contacts</field>
<field name="res_model">res.partner</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="configuration_menu" name="Configuration"
parent="main_openacademy_menu"/>
<menuitem id="contact_menu" name="Contacts"
parent="configuration_menu"
action="contact_list_action"/>
</data>
</openerp>

I guess that reference to 'instructor' field in view should be changed somehow to make it clear it does not belong to parent model, but to inherited one. 

Any help would be appreciated. Thanks in advance.




Аватар
Відмінити
Автор Найкраща відповідь

Thanks, Pawan. I both updated the module and restarted the server. Unfortunately, error appears the same.

Thank for your reply, Akhil. That is the first code I tried. I just returned it according to the way you suggested, and it did not work. I had previously set up two VMs for my tests. I was working in Odoo version 8. After restarting server, along with error at web browser, the log file shows this:

ProgrammingError: column res_partner.instructor does not exist
LINE 1: ...artner"."credit_limit","res_partner"."country_id","res_partn...
^

However, I did the same in Odoo 9, and it is working fine (!). This somewhat baffling to me, since I had previously tried with that code with no success.

Do you know if Odoo version, 8 or 9, this has something to do with this?

Best regards to both of you.

Аватар
Відмінити
Найкраща відповідь

Raul,

Try restarting server by upgrading your module(and Db also if you are having multiple DB's)...

Hope it helps!

Аватар
Відмінити
Найкраща відповідь

Hi,

You can do the coding either in new api or old api. But here, you are missing them in field definition part which is not in the proper way.

Try like this:

from openerp import models, fields, api
class Partner(models.Model):
    _inherit = 'res.partner'

    instructor = fields.Boolean("Instructor", default=False)
session_ids = fields.Many2many('openacademy.session',string="Sesiones Atendidas", readonly=True)

The tutorial is according to the new api. So please follow like that, because the inheriting classes and libraries are different for them. 

There is nothing wrong with your view definition.

Make sure that you have imported this py file in __init__.py and also added the view file in __openerp__.py

Restart the server n try.

Hope this helps!

Аватар
Відмінити
Related Posts Відповіді Переглядів Дія
2
лют. 19
3955
2
черв. 16
5895
2
лист. 23
3281
3
груд. 22
7242
3
лист. 22
7252