[FIX] base, hr_timesheet: display negative float_time values

Before this commit, negative values in a float field interpreted as time
(i.e. unit_amount on analytic lines) were wrongly formatted

After this commit, not only we correct the hr_timesheet qweb templates
but we also correct the qweb widget to handle the case

OPW 1869986
closes #26024
This commit is contained in:
Lucas Perais (lpe)
2018-07-30 13:18:04 +02:00
parent 91d647ecf7
commit 44ea58234e
2 changed files with 8 additions and 4 deletions
@@ -44,7 +44,7 @@
<t t-if="l.task_id"><span t-field="l.task_id.name"/></t>
</td>
<td class="text-right">
<span t-esc="'%s:%02.0f' % tuple(int(round(x)) for x in divmod(l.unit_amount*60,60))"/>
<span t-field="l.unit_amount" t-options="{'widget': 'float_time'}"/>
</td>
</tr>
</t>
@@ -53,7 +53,9 @@
<td />
<td t-if="show_task"/>
<td class="text-right"><strong>Total</strong></td>
<td class="text-right"><strong t-esc="'%s:%02.0f' % tuple(int(round(x)) for x in divmod(sum(docs.mapped('unit_amount'))*60,60))"/></td>
<t t-set="total_value" t-value="sum(docs.mapped('unit_amount'))" />
<t t-set="sign" t-value="'-' if total_value &lt; 0 else ''"/>
<td class="text-right"><strong t-esc="sign + '%s:%02.0f' % tuple(int(round(x)) for x in divmod(abs(total_value)*60,60))"/></td>
</tr>
</tbody>
</table>
+4 -2
View File
@@ -7,6 +7,7 @@ from odoo import api, fields, models, _
from PIL import Image
import babel
from lxml import etree
import math
from odoo.tools import html_escape as escape, posix_to_ldml, safe_eval, float_utils, format_date, pycompat
@@ -367,8 +368,9 @@ class FloatTimeConverter(models.AbstractModel):
@api.model
def value_to_html(self, value, options):
hours, minutes = divmod(value * 60, 60)
return '%02d:%02d' % (hours, minutes)
sign = math.copysign(1.0, value)
hours, minutes = divmod(abs(value) * 60, 60)
return '%02d:%02d' % (sign * hours, minutes)
class DurationConverter(models.AbstractModel):