This question has been flagged
4974 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>

Avatar
Discard