Odoo Help


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.


How to use the self.env.

Giovanny Vizcaya
on 11/2/15, 8:47 PM 1,227 views

Good day, i'm working with odoo8 developing a module that check the payments of employees social benefits. I need to get the last value inserted in a field "accumulated, i'm trying with this code:


def _get_sum_payment(self):

payments = self.env['hr.prestaciones'].search([(employee_id','=', self.employee_id),('accumulated')])

self.sum_payments = sum(item.amount for item in payments)

sum_payments = fields.Float(string="Prestaciones Acumuladas", compute='_get_sum_payment')

but that code is not working... how can solve it?



| 5 4 8
Kochi, India
ODOO technical and functional

        I like learning new thing, especially technical thing. I am a quick learner, I can learn technical things very fast. I have good logical skill,  I have immense interest in programming.

e-mail id : baijuks@hotmail.com

On 11/2/15, 11:59 PM


    env(Environment) in new API is to provide an encapsulation around cursor, user_id, model, and context, Recordset and caches.

It evades the use of infamous function signature def afun(self, cr, uid, ids, context=None): and in new API its def afun(self):

And if you want to call ORM method directly from an object you can use self.env['obj'].method instead of self.method

An environment wraps data for ORM records:

  • 'cr', the current database cursor.

  • 'uid', the current user id.

  • 'context', the current context dictionary.

For more about env: Link

For getting the value of accumulated from last record of 'hr.prestaciones' you can use this script:-

payments = self.env['hr.prestaciones'].search([])[0].accumulated

Hope this helps.

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)


Asked: 11/2/15, 8:47 PM
Seen: 1227 times
Last updated: 11/3/15, 2:25 AM