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 use ORM methods, to get the required data ?

By
luis
on 7/9/13, 5:19 PM 912 views

I need to get the value of field in a tree view of the fields_view_get method and a I use ORM methods to achieve this. my code :

class res_partner(osv.osv):

_inherit = 'res.partner'


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


    if context is None:
        context = {}

    partner_obj = self.pool.get('res.partner')
    ids_partner = partner_obj.search(cr, uid, [], context=context)              
    element = partner_obj.browse(cr,uid,ids_partner[0]).numcte

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


    newcte=test_name.numcte


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

    if view_type == 'tree':

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

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


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

 res_partner()

My problem is when I, use for instance :

 element = partner_obj.browse(cr,uid,ids_partner[0]).numcte

It returns me the value of the field that I want, but in the treeView is the same for each row, like this A001, A001, A001, in instead of A001, A002, A003.

in this case ids_partner[0], How can I make this number to be dynamic and changing for each row ?

Or in the case that use this:

 my_data  = partner_obj.read(cr, uid, ids_partner, ["numcte"], context=context)

returns me the tuple like this:

[{'numcte': u'A001', 'id': 3}, {'numcte': u'A002', 'id': 2}, {'numcte': u'A003', 'id': 4}] [{'numcte': u'A001', 'id': 3}, {'numcte': u'A002', 'id': 2}, {'numcte': u'A003', 'id': 4}] [{'numcte': u'A001', 'id': 3}, {'numcte': u'A002', 'id': 2}, {'numcte': u'A003', 'id': 4}]

one for each row

How can I get the value of the field that I want for the correct row. ?

thank you all for your time, I been a while in this so any help is usefull.

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: 7/9/13, 5:19 PM
Seen: 912 times
Last updated: 3/16/15, 8:10 AM