Odoo Help


name_get cannot parse context value to tree view

on 8/6/13, 6:54 AM 2,212 views

I am trying to read the show the partner's 'country' in the quotation tree list. In order to so, I was trying to write a test module first in order to know how name_get works.

Below are my relevant codes. I can get the correct context selection in Form view (the classroom are shown as 'number'), but in the tree view, all classroom are shown as 'location'.

If my approach is not right (no matter whether the test module is working or not), please kindly advise. My main purpose is to show the partner's country in the quotation's tree list.

Many thanks in advance!

file classroom.py:

from openerp.osv import osv, fields

class oecn_training_classroom(osv.osv): _name='oecn.training.classroom' _description='OECN Classroom' _columns={ 'number':fields.char('Number', size=64), 'capacity':fields.integer('Capacity'), 'location':fields.char('Location', size=125), }

def name_get(self, cr, uid, ids, context=None):
    if context is None:
        context = {}
    if isinstance(ids, (int, long)):
        ids = [ids]
    res = []
    for record in self.browse(cr, uid, ids, context=context):
        if context.get('number'):
            name = record.number
            name = record.location

        if record.parent_id and not record.is_company:
            name =  "%s, %s" % (record.parent_id.name, name)
        if context.get('show_address'):
            name = name + "\n" + self._display_address(cr, uid, record, without_company=True, context=context)
            name = name.replace('\n\n','\n')
            name = name.replace('\n\n','\n')
        if context.get('show_email') and record.email:
            name = "%s <%s>" % (name, record.email)
        res.append((record.id, name))
    return res


file lesson.py

from openerp.osv import osv, fields

class oecn_training_lesson(osv.osv): _name='oecn.training.lesson' _inherit='oecn.training.lesson' _columns={ #'nametest':fields.char('ThisIsTest', size=64), 'classroom_id':fields.many2one('oecn.training.classroom','Classroom'),




<openerp> <data> <record model="ir.ui.view" id="oecn_training_lesson_form_inherit_classroom_view"> <field name="name">Classroom inherited view</field> <field name="model">oecn.training.lesson</field> <field name="inherit_id" ref="oecn_training.oecn_training_lesson_form_view"/> <field name="arch" type="xml">
<data> <field name="name" position="after"> <field name="classroom_id" context="{'number': 1}" options="{"always_reload": True}"/> </field>


    <record model="ir.ui.view" id="oecn_training_lesson_inherit_tree_view">
        <field name="name">Inherited Lesson List</field>
        <field name="model">oecn.training.lesson</field>
        <field name="inherit_id" ref="oecn_training.oecn_training_lesson_tree_view"/>
        <field name="arch" type="xml">
                <field name="name" position="after">
                    <field name="classroom_id" context="{'number': 1}" options='{"always_reload": True}'/>




About This Community

This platform 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.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 8/6/13, 6:54 AM
Seen: 2212 times
Last updated: 3/16/15, 8:10 AM