[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:
@@ -44,7 +44,7 @@
|
|||||||
<t t-if="l.task_id"><span t-field="l.task_id.name"/></t>
|
<t t-if="l.task_id"><span t-field="l.task_id.name"/></t>
|
||||||
</td>
|
</td>
|
||||||
<td class="text-right">
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</t>
|
</t>
|
||||||
@@ -53,7 +53,9 @@
|
|||||||
<td />
|
<td />
|
||||||
<td t-if="show_task"/>
|
<td t-if="show_task"/>
|
||||||
<td class="text-right"><strong>Total</strong></td>
|
<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 < 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>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from odoo import api, fields, models, _
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
import babel
|
import babel
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
|
import math
|
||||||
|
|
||||||
from odoo.tools import html_escape as escape, posix_to_ldml, safe_eval, float_utils, format_date, pycompat
|
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
|
@api.model
|
||||||
def value_to_html(self, value, options):
|
def value_to_html(self, value, options):
|
||||||
hours, minutes = divmod(value * 60, 60)
|
sign = math.copysign(1.0, value)
|
||||||
return '%02d:%02d' % (hours, minutes)
|
hours, minutes = divmod(abs(value) * 60, 60)
|
||||||
|
return '%02d:%02d' % (sign * hours, minutes)
|
||||||
|
|
||||||
|
|
||||||
class DurationConverter(models.AbstractModel):
|
class DurationConverter(models.AbstractModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user