diff options
| author | Richard Mathot <rim@odoo.com> | 2018-08-06 15:19:16 +0200 |
|---|---|---|
| committer | Richard Mathot <rim@odoo.com> | 2018-08-07 07:36:49 +0200 |
| commit | c5d95f1b3783f7863bcb7c643b8bd54ae00fce77 (patch) | |
| tree | 3899d7a3cc93f11a858e48bdacc1c3da57d0818e | |
| parent | 1369272f1af324dc2c3f7162b8c8a5887263b722 (diff) | |
[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
| -rw-r--r-- | addons/resource/models/resource.py | 4 |
1 files 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): |
