[FIX] resource: don't lose minutes anymore

In resource.calendar.attendance, we store the start and end hour of an
interval as floats.

eg: 17 hours 9 minutes is stored as 17.15

When converting this float to a datetime object, the method
float_to_time always rounds down the value, which may be wrong if, due
to float imprecisions, 0.15 hours is converted to 8.999... minutes (and
was then rounded to 8).

We do fix this behaviour by rounding to the closest integer.

Thanks to @jem-odoo for his help troubleshooting this issue.

opw-1872166
This commit is contained in:
Richard Mathot
2018-08-07 07:36:49 +02:00
parent 1369272f1a
commit c5d95f1b37
+2 -2
View File
@@ -14,13 +14,13 @@ from operator import itemgetter
from odoo import api, fields, models, _
from odoo.addons.base.res.res_partner import _tz_get
from odoo.exceptions import ValidationError
from odoo.tools.float_utils import float_compare
from odoo.tools.float_utils import float_compare, float_round
def float_to_time(float_hour):
if float_hour == 24.0:
return datetime.time.max
return datetime.time(int(math.modf(float_hour)[1]), int(60 * math.modf(float_hour)[0]), 0)
return datetime.time(int(math.modf(float_hour)[1]), int(float_round(60 * math.modf(float_hour)[0], precision_digits=0)), 0)
def to_naive_user_tz(datetime, record):