Skip to Content
Menu
This question has been flagged
4 Replies
2731 Views



when i add a new payment(1), this is added to the accumulated(2) and showing a new accumulated(3) ...how can i do that? 

Avatar
Discard
Author Best Answer

i tried to get the last value of "Prestaciones Acumuladas" but i don't understand how it works, i'm using


@api.one

def _get_sum_payment(self):

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

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

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

Avatar
Discard
Best Answer

To do that you need to have the field "Prestaciones Acumuladas" as a calculated field with store = True and also readonly to do not modify it latter at least that you made a change in the field "Abono Mensual" of previous saved values. The formula to calculate it's simply the sum of the field "Abono Mensual" + the field "Prestaciones Acumuladas" of the previous record. You just need to figure out how to get the previous record, could be based on the field create_date like a search over the model with a create_date minor than the current record create_date with a limit 1 of results and ordered by create_date DESC


Avatar
Discard
Author

you mean prestaciones_acumuladas = fields.Float(compute="_get_acumulado")? but i don't understand at all that part of get the previous record...

Author

Something like this? perhaps? @api.one def _get_sum_payment(self): payment = self.env['account.voucher'].search([('partner_id','=', self.id),('type','=','payment')]) self.sum_payments = sum(item.amount for item in payment) sum_payments = fields.Float(string="# Sum", compute='_get_sum_payment')

Related Posts Replies Views Activity
1
Aug 23
12549
1
Aug 23
11054
1
Jul 23
7228
4
Apr 23
8677
2
Feb 23
17598