From c0028af4b64caa9f3cb9515a3b9b676f4e131d03 Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Mon, 25 Jun 2018 00:19:33 +0200 Subject: [PATCH] =?UTF-8?q?[FIX][TASK=200048k]=20Revert=20info=20=C3=A0=20?= =?UTF-8?q?supprimer=20quand=20worker=20id=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- beesdoo_shift/models/task.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/beesdoo_shift/models/task.py b/beesdoo_shift/models/task.py index 9ed1f6b..8043670 100644 --- a/beesdoo_shift/models/task.py +++ b/beesdoo_shift/models/task.py @@ -36,7 +36,7 @@ class Task(models.Model): color = fields.Integer(related="stage_id.color", readonly=True) is_regular = fields.Boolean(default=False) replaced_id = fields.Many2one('res.partner', track_visibility='onchange', domain=[('eater', '=', 'worker_eater')]) - revert_info = fields.Text() + revert_info = fields.Text(copy=False) working_mode = fields.Selection(related='worker_id.working_mode') def message_auto_subscribe(self, updated_fields, values=None): @@ -80,11 +80,21 @@ class Task(models.Model): def write(self, vals): """ Overwrite write to track stage change + If worker is changer: + Revert for the current worker + Change the worker info + Compute stage change for the new worker """ + if 'worker_id' in vals: + for rec in self: + if rec.worker_id != vals['worker_id']: + rec._revert() + super(Task, rec).write({'worker_id': vals['worker_id']}) + rec._update_stage(rec.stage_id.id) if 'stage_id' in vals: for rec in self: if vals['stage_id'] != rec.stage_id.id: - rec._update_stage(rec.stage_id.id, vals['stage_id']) + rec._update_stage(vals['stage_id']) return super(Task, self).write(vals) def _set_revert_info(self, data, status): @@ -104,7 +114,7 @@ class Task(models.Model): self.env['cooperative.status'].browse(data['status_id']).sudo()._change_counter(data['data']) self.revert_info = False - def _update_stage(self, old_stage, new_stage): + def _update_stage(self, new_stage): self.ensure_one() self._revert() update = int(self.env['ir.config_parameter'].get_param('always_update', False))