Skip to Content
Menu
This question has been flagged
1 Reply
2532 Views

Hi forum!


I have this char field:

overtime = fields.Char(readonly=True, default='00:00')

I would need to summarize the values ​​of the overtime field, and I want to print this value in a new field.

This is how the values ​​appear in the overtime field:

02:00
00:00
01:00
00:00
03:00
00:00
00:00
02:00
00:00
01:00
01:00

Is it possible to do it?


Thanks for your help!

Regards,

Steven

Avatar
Discard
Best Answer

Hi Steven:

Here's an example of how it can be done. You will need to replace the array with the appropriate recordset returned by a search statement.

from datetime import time

ots = ['02:00','01:50','00:10','03:15']

tot = 0
for ot in ots:
t = time.fromisoformat(ot)
tot += t.hour*60 + t.minute

print('%s:%s' % (str(int(tot/60)).zfill(2), str(tot%60).zfill(2)))

Hope this helps.

Avatar
Discard
Author

Thank you Paresh Wagh! Thanks for the great help!

Author

I had to convert the string type to a float. But when I reference the sum_50_overtime field with a related field, it doesn't get the value.

0 is the value of the sum_50_overtime field, but i don't know why.

But when I print to the console, it gets the correct value, only the related field does not.

sum_50_overtime = fields.Float(compute='_compute_sum_50')

@api.multi
@api.depends('overtime_50', 'sum_50_overtime')
def _compute_sum_50(self):
ots = []
for record in self:
ots.append(record.overtime_50)
tot = 0
for ot in ots:
t = parser.parse(ot)
tot += t.hour * 60 + t.minute
s = ('%s:%s' % (str(int(tot / 60)).zfill(2), str(tot % 60).zfill(2)))
time = float(s.replace(":", ""))
record.sum_50_overtime = time
print(record.sum_50_overtime)

The related field :

overtime_weekdays = fields.Float(related='attendance_ids.sum_50_overtime')

Thank you for your help!

Related Posts Replies Views Activity
1
Mar 18
5786
3
Jul 24
21368
2
Dec 24
61
0
Dec 24
59
2
Jul 24
942