Skip to content
Snippets Groups Projects
Commit ab487982 authored by Thibault Francois's avatar Thibault Francois
Browse files

[FIX] timer, hr_timesheet: Fix _compute_display_timer_buttons


mixin method should not return in the middle of the loop
Use the value updated on the record instead

super() is called with self at every iteration
which is not very efficient and can be wrong

Solution call super for each specific record
and only when needed

write is not a good practice in compute method

closes odoo/odoo#52858

X-original-commit: 7e19ed98d18305370b5c14edd3d310cfea5df714
Related: odoo/enterprise#11100
Signed-off-by: default avatarYannick Tivisse (yti) <yti@odoo.com>
parent a8ed0c00
Branches
Tags
No related merge requests found
......@@ -142,24 +142,27 @@ class Task(models.Model):
@api.depends('display_timesheet_timer', 'timer_start', 'timer_pause', 'total_hours_spent')
def _compute_display_timer_buttons(self):
for task in self:
displays = super()._compute_display_timer_buttons()
start_p, start_s, stop, pause, resume = displays['start_p'], displays['start_p'], displays['stop'], displays['pause'], displays['resume']
if not task.display_timesheet_timer:
start_p, start_s, stop, pause, resume = False, False, False, False, False
task.update({
'display_timer_start_primary': False,
'display_timer_start_secondary': False,
'display_timer_stop': False,
'display_timer_pause': False,
'display_timer_resume': False,
})
else:
super(Task, task)._compute_display_timer_buttons()
task.display_timer_start_secondary = task.display_timer_start_primary
if not task.timer_start:
stop, pause, resume = False, False, False
task.update({
'display_timer_stop': False,
'display_timer_pause': False,
'display_timer_resume': False,
})
if not task.total_hours_spent:
start_s = False
task.display_timer_start_secondary = False
else:
start_p = False
task.write({
'display_timer_start_primary': start_p,
'display_timer_start_secondary': start_s,
'display_timer_stop': stop,
'display_timer_pause': pause,
'display_timer_resume': resume,
})
task.display_timer_start_primary = False
@api.depends('project_id.analytic_account_id.active')
def _compute_analytic_account_active(self):
......
......@@ -119,13 +119,12 @@ class TimerMixin(models.AbstractModel):
pause = False
else:
resume = False
record.write({
record.update({
'display_timer_start_primary': start_p,
'display_timer_stop': stop,
'display_timer_pause': pause,
'display_timer_resume': resume,
})
return {'start_p': start_p, 'stop': stop, 'pause': pause, 'resume': resume}
@api.model
def _timer_rounding(self, minutes_spent, minimum, rounding):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment