From ab48798229d4c756ab31fd0f1fa5518ef8e63037 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Thu, 11 Jun 2020 11:32:58 +0000 Subject: [PATCH] [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: Yannick Tivisse (yti) --- addons/hr_timesheet/models/project.py | 29 +++++++++++++++------------ addons/timer/models/timer_mixin.py | 3 +-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/addons/hr_timesheet/models/project.py b/addons/hr_timesheet/models/project.py index 0ee5fd58103..686acad3409 100644 --- a/addons/hr_timesheet/models/project.py +++ b/addons/hr_timesheet/models/project.py @@ -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): diff --git a/addons/timer/models/timer_mixin.py b/addons/timer/models/timer_mixin.py index 201628a16af..4c39587641c 100644 --- a/addons/timer/models/timer_mixin.py +++ b/addons/timer/models/timer_mixin.py @@ -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):