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 can I loop and access values of fields in OpenERP?

By
Yakito
on 2/12/13, 9:06 PM 2,103 views

I am learning to develop OpenERP modules, and one of the things I need to do is calculate the average of all the inputs from the user.

My idea was to loop the records while keeping the sum and the count and then make the average, but I can't seem to understand how to access the value for the total field for each record in the sim.students table

Here is part of my code

def get_text(self, cr, uid, ids, fields, arg, context):
    result = {}
    i = 0
    for id in ids:
        print self.browse(cr,uid,id,['total'])
        print id
        i = i+1
        print i

    return result

But the result of printing self.browse(cr,uid,id,['total']) returns me browse_record(sim.student, 3) and not the total itself.

I know this must be really simple but I can't seem to figure out how to get to that value.

Any tip much appreciated

1
Mario Arias Badila
On 2/12/13, 11:58 PM

You need to change it to

print self.browse(cr,uid,id).total

self.browse returns a browsable object, and then you can access it's fields...

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: 2/12/13, 9:06 PM
Seen: 2103 times
Last updated: 3/16/15, 8:10 AM