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 show a column on tree

By
Javier Batres Velásquez
on 1/22/15, 10:10 AM 766 views

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

1

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

 

 

1
Bruno PLANCHER
On 1/26/15, 10:03 AM

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

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: 1/22/15, 10:10 AM
Seen: 766 times
Last updated: 3/16/15, 8:10 AM