Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odpovědět
28431 Zobrazení

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:


@api.one

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?

Avatar
Zrušit
Nejlepší odpověď

Hi,

    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.

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
2
srp 23
2706
2
pro 22
14110
1
lis 21
4267
1
led 21
3900
0
led 21
1773