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

name_get cannot parse context value to tree view

By
Yao
on 8/6/13, 6:54 AM 1,544 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
        else:
            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

oecn_training_classroom()

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'),

          }

oecn_training_lesson()

lesson_ciew.xml:

<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>
</data>

        </field>
    </record>

    <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">
            <data>
                <field name="name" position="after">
                    <field name="classroom_id" context="{'number': 1}" options='{"always_reload": True}'/>
                </field>                                    

            </data>
        </field>
    </record>

</data>

</openerp>

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

0 follower(s)

Stats

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