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.

1

How to use acive_id on fields_view_get ?

By
luis
on 6/11/13, 6:31 PM 4,531 views

Hi, I'm using fields_view_get method for overriding a treeview, every thing is fine but when I try to get the active_id to return the value of the current record, it returns False, this is my code :

class res_partner(osv.osv):

_inherit = 'res.partner'


def fields_view_get(self, cr, uid, view_id=None, view_type='tree', context=None, toolbar=False, submenu=False):



    if context is None:
        context = {}


    res = super(res_partner,self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=submenu)

    partner_obj = self.pool.get('res.partner')
    active_id = context.get('active_id', False)
    partner_name = partner_obj.browse(cr, uid, active_id, context=context).numcte
    partner_icon = partner_name
    print partner_icon  
    print active_id

    doc = etree.XML(res['arch'])

    if view_type == 'tree':

        for node in doc.xpath("//button[@name='icono']"):
               node.set('icon', partner_icon)   

    res['arch'] = etree.tostring(doc)
    return res


_columns = {
    'numcte': fields.text('numero cliente'),
}

res_partner()

thanks, for your advice.

0
Danimar Ribeiro
On 4/14/16, 7:19 AM

For your specific case you should override "read". 

"fields_view_get" does not have information about the current record, what you could if you want to is pass through context the id, but it's not the best, use "read".


@api.multi

def read(self, fields=None, load='_classic_read'):


0
Omar OUHARI
On 1/27/16, 3:25 PM

I have the same issue. did you find any solution. I want to set value of current record for each field. thanks to any answer.

0

Grover Menacho

--Grover Menacho--
2523
| 5 7 8
La Paz, Bolivia
--Grover Menacho--

Systems Engineer + MBA

Grover Menacho
On 6/11/13, 7:18 PM

I know that there is no active_id when you are calling a tree, I use that when i select some rows on a tree and then I call a wizard or something there you have active_ids because you selected some rows. If you are calling a tree view, there is no rows selected so there is no active_id present.

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: 6/11/13, 6:31 PM
Seen: 4531 times
Last updated: 4/14/16, 7:19 AM