[FIX] base: negative duration correct html render

Step to reproduce:
- Render negative duration with the duration widget

Example V15:
- Create timesheet entry with negative duration (e.g. -00:30)
- Print the timesheet entry

Current Behaviour:
- Time is rendered as Time-1h (in e.g. -01:30)

Behaviour after PR:
- Time is correctly rendered (in e.g. -00:30)

opw-2731186

closes odoo/odoo#86360

X-original-commit: a45e2c03e26034f683a692d9c93e26925f7c2a21
Signed-off-by: Damhaut Florian (flda) <flda@odoo.com>
This commit is contained in:
Florian Damhaut
2022-03-14 17:28:34 +00:00
parent a87dd572a4
commit baab0528fd
2 changed files with 14 additions and 8 deletions
+9 -8
View File
@@ -577,6 +577,10 @@ class DurationConverter(models.AbstractModel):
r = round((value * factor) / round_to) * round_to
sections = []
sign = ''
if value < 0:
r = -r
sign = '-'
if options.get('digital'):
for unit, label, secs_per_unit in TIMEDELTA_UNITS:
@@ -585,14 +589,9 @@ class DurationConverter(models.AbstractModel):
v, r = divmod(r, secs_per_unit)
if not v and (secs_per_unit > factor or secs_per_unit < round_to):
continue
if len(sections):
sections.append(':')
sections.append("%02.0f" % int(round(v)))
return ''.join(sections)
sections.append(u"%02.0f" % int(round(v)))
return sign + u':'.join(sections)
if value < 0:
r = -r
sections.append('-')
for unit, label, secs_per_unit in TIMEDELTA_UNITS:
v, r = divmod(r, secs_per_unit)
if not v:
@@ -607,7 +606,9 @@ class DurationConverter(models.AbstractModel):
if section:
sections.append(section)
return ' '.join(sections)
if sign:
sections.insert(0, sign)
return u' '.join(sections)
class RelativeDatetimeConverter(models.AbstractModel):
@@ -333,6 +333,11 @@ class TestDurationExport(TestBasicExport):
result = converter(72, {'unit': 'second'}, {'lang': 'fr_FR'})
self.assertEqual(result, u"1 minute 12 secondes")
def test_negative_digital(self):
converter = self.get_converter('float', 'duration')
result = converter(-90, {'unit': 'minute', 'round': 'minute', 'digital': True}, {'lang': 'fr_FR'})
self.assertEqual(result, u'-01:30')
class TestRelativeDatetime(TestBasicExport):
# not sure how a test based on "current time" should be tested. Even less