This question has been flagged

Hello I am trying to show a field of my foreign key on my tree. for example

<tree string="Course Tree">

          <field name="responsible_id.partner_nit"/> <!-- This is the field that I want to show. -->

</tree>

Note: this is inside a record where the model is "session" but "responsuble_id" is a Many2one relationship whit "res.partner"

I can't find a form for this. Thank yout for all the help

Avatar
Discard
Author Best Answer

Hello i have solved that reading more crefully the ORM Documentation.

In the paste the fields.realted() was sucessfull, but now on the version 8, the sintaxis is:

nit = field.<Type of data>(related="field on model.information", store=False)

I wait that this be usefull for someone more.

 

Thanks for all the help

 

 

Avatar
Discard
Best Answer

Hello javier,

As long as I know, this not possible to display a field from another model using the Many2One directly.

Also, you can create a related field in your model, which will automatically retrieve the value of partner_nit. For example: 

'responsible_partner_nit': fields.related('responsible_id', 'partner_nit', 'Partner NIT')

And you display this new field in your tree view.

 

Notes: If you want to filter your list with this new field (sorting or filtering the list), you have to add a store parameter to your field definition (in Python model) so that Odoo will store the value in DB, re-compute it only when needed, and wil be able fo filter on this field: 

def _get_session_from_partner(self, cr, uid, ids, context=None) {

    return self.pool.get('your.model.session').search(cr, uid, [('responsible_id.id', 'in', ids')], context=context)

}

_columns = {

    

'    responsible_partner_nit': fields.related('responsible_id', 'partner_nit', 'Partner NIT',

            store={'your.model.session': lambda *a: self, cr, uid, ids, ctx: ids, ['responsible_id'], 10],

                'res.partner':[_get_session_from_partner, ['partner_nit'], 11})

}

Hope it helps you,

Regards

Avatar
Discard