Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How to use a new field added in a inherited model into a view?

By
Raúl Carpio
on 4/27/16, 2:56 PM 786 views

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.




0
Raúl Carpio
On 4/28/16, 12:05 PM

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.

0

Pawan

--Pawan--
1267
| 4 3 5
Hyderabad, India
--Pawan--


Pawan
On 4/28/16, 1:17 AM

Raul,

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

Hope it helps!

0

Akhil P Sivan

--Akhil P Sivan--
3423
| 5 3 6
Kochi, India
--Akhil P Sivan--

Interested in exploring Odoo both technically & functionality wise.

email-id : akhilpsivan01@gmail.com

Akhil P Sivan
On 4/28/16, 12:49 AM

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!

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 4/27/16, 2:56 PM
Seen: 786 times
Last updated: 4/28/16, 12:05 PM