Suppose I have two float fields:
num = fields.Float('Number')
sum_num = fields.Float('Sum all values of the num field')
I created the first records and put value: 1.0 in the num field ;
num = 1.0
and want the result in the sum_num field is 1.0 ;
sum_num = 1.0
Then I created the second record and put value: 2.0 in the num field ;
num = 2.0
and want the result in the sum_num field is 3.0 ;
sum_num = 3.0
and so on...
I'd tried to used compute field like this:
sum_num = fields.Float(compute='_sum_num', string='Sum all values of all records of the num field')
@api.depends('num')
def _sum_num(self):
for rec in self:
if rec.num:
rec.sum_num += rec.sum
But I got the error with this way!
So how do sum all values of all records of the num field?
Please help!
Thank you!