[FIX] base: widget duration - allow to round to avoid seconds
Allow to round the duration to a minimal unit.
Eg:
0.33 hour = 19.8 min = "19 minutes 48 seconds"
if option {'widget'='duration', 'unit'='hour', 'round'='minute'}
0.33 hour => 20 min = "20 minutes"
This commit is contained in:
@@ -45,7 +45,7 @@ class event_track(models.Model):
|
||||
'Status', default='draft', required=True, copy=False, track_visibility='onchange')
|
||||
description = fields.Html('Track Description', translate=True)
|
||||
date = fields.Datetime('Track Date')
|
||||
duration = fields.Float('Duration', digits=(16, 2), default=1.5)
|
||||
duration = fields.Float('Duration', default=1.5)
|
||||
location_id = fields.Many2one('event.track.location', 'Room')
|
||||
event_id = fields.Many2one('event.event', 'Event', required=True)
|
||||
color = fields.Integer('Color Index')
|
||||
|
||||
@@ -249,7 +249,7 @@
|
||||
<b>Date</b><br/>
|
||||
<span t-field="track.date" t-field-options='{"hide_seconds":"True"}'/><br/>
|
||||
<b>Duration</b><br/>
|
||||
<span t-field="track.duration" t-field-options="{"widget": "duration", "unit": "hour"}"/><br/>
|
||||
<span t-field="track.duration" t-field-options='{"widget": "duration", "unit": "hour", "round": "minute"}'/><br/>
|
||||
<b>Location</b><br/>
|
||||
<span t-field="track.location_id"/><br/>
|
||||
</div>
|
||||
|
||||
@@ -942,7 +942,12 @@ class DurationConverter(osv.AbstractModel):
|
||||
factor = units[options['unit']]
|
||||
|
||||
sections = []
|
||||
|
||||
r = value * factor
|
||||
if options.get('round') in units:
|
||||
round_to = units[options['round']]
|
||||
r = round(r / round_to) * round_to
|
||||
|
||||
for unit, secs_per_unit in TIMEDELTA_UNITS:
|
||||
v, r = divmod(r, secs_per_unit)
|
||||
if not v: continue
|
||||
|
||||
Reference in New Issue
Block a user