From eb290800804d6a9a8b52eed1b3d80cb1df6b2885 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Wed, 7 Feb 2024 17:35:41 +0100 Subject: [PATCH] =?UTF-8?q?[IMP]=20project=5Fworkload:=C2=A0Improve=20work?= =?UTF-8?q?load=20sync=20inheritance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- project_workload/models/project_task.py | 47 ++++++++++++++----- .../models/project_task_workload.py | 4 +- project_workload/views/project_task_view.xml | 38 +++++++-------- 3 files changed, 56 insertions(+), 33 deletions(-) diff --git a/project_workload/models/project_task.py b/project_workload/models/project_task.py index 317fccf6..42fca877 100644 --- a/project_workload/models/project_task.py +++ b/project_workload/models/project_task.py @@ -46,26 +46,49 @@ def _compute_workload_ids(self): ): continue - vals = record._prepare_workload() - # Handle only one workload in automatic - if record.workload_ids: - # Remove other workloads and update the first workload values - record.workload_ids = [ - (1, record.workload_ids[0].id, vals), - *[(2, workload_id.id) for workload_id in record.workload_ids[1:]], - ] - else: - # Create the workload - record.workload_ids = [(0, 0, vals)] + record.workload_ids = record._get_workload_sync() - def _prepare_workload(self): + def _prepare_workload(self, **extra): return { "date_start": self.date_start, "date_end": self.date_end, "hours": self.planned_hours, "user_id": self.user_id.id, + **extra, } + def _get_workload_sync(self): + self.ensure_one() + return [ + *[(0, 0, vals) for vals in self._get_new_workloads()], + *[ + (1, workload_id.id, vals) + for workload_id, vals in self._get_updated_workloads() + ], + *[(2, workload_id.id) for workload_id in self._get_obsolete_workloads()], + ] + + def _get_new_workloads(self): + self.ensure_one() + # Handle only one workload in automatic + if not self.workload_ids: + return [self._prepare_workload()] + return [] + + def _get_updated_workloads(self): + self.ensure_one() + # Remove other workloads and update the first workload values + if self.workload_ids: + return [(self.workload_ids[0], self._prepare_workload())] + return [] + + def _get_obsolete_workloads(self): + self.ensure_one() + # Remove other workloads and update the first workload values + if len(self.workload_ids) > 1: + return self.workload_ids[1:] + return [] + @api.depends("workload_ids.unit_ids") def _compute_workload_unit_ids(self): # related doesn't retrieve all the data so we need to compute it diff --git a/project_workload/models/project_task_workload.py b/project_workload/models/project_task_workload.py index 04c878c8..7b5cee41 100644 --- a/project_workload/models/project_task_workload.py +++ b/project_workload/models/project_task_workload.py @@ -103,9 +103,9 @@ def name_get(self): for task in self: if not task.date_start or not task.date_end: continue - week_start = f"Load {week_name(task.date_start)}" + week_start = week_name(task.date_start) week_end = week_name(task.date_end - timedelta(days=7)) - name = f"{week_start}" + name = f"{_('Load')} {week_start}" if week_end > week_start: name += f" - {week_end}" name += f": {task.hours}h" diff --git a/project_workload/views/project_task_view.xml b/project_workload/views/project_task_view.xml index b13818f3..b8339fee 100644 --- a/project_workload/views/project_task_view.xml +++ b/project_workload/views/project_task_view.xml @@ -17,26 +17,26 @@ + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - -