From c5d95f1b3783f7863bcb7c643b8bd54ae00fce77 Mon Sep 17 00:00:00 2001 From: Richard Mathot Date: Mon, 6 Aug 2018 15:19:16 +0200 Subject: [PATCH] [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 --- addons/resource/models/resource.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/resource/models/resource.py b/addons/resource/models/resource.py index bed0ac22d4e..ebe4fd24066 100644 --- a/addons/resource/models/resource.py +++ b/addons/resource/models/resource.py @@ -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):