From b5e414bac401f24076b79b7f88edef0950069123 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Mon, 23 Sep 2024 16:32:02 +0200 Subject: [PATCH] project_workload: add view to see load, automatically set done load when the task is closed --- project_workload/__manifest__.py | 1 + .../models/project_workload_unit.py | 17 ++++- project_workload/views/menu_view.xml | 8 +++ .../views/project_task_workload_unit_view.xml | 66 +++++++++++++++++++ .../models/project_workload_unit.py | 9 ++- 5 files changed, 96 insertions(+), 5 deletions(-) create mode 100644 project_workload/views/project_task_workload_unit_view.xml diff --git a/project_workload/__manifest__.py b/project_workload/__manifest__.py index 8b4d7f55..a42124b8 100644 --- a/project_workload/__manifest__.py +++ b/project_workload/__manifest__.py @@ -21,6 +21,7 @@ "views/project_task_workload_view.xml", "views/project_task_view.xml", "views/project_project_view.xml", + "views/project_task_workload_unit_view.xml", "views/menu_view.xml", ], } diff --git a/project_workload/models/project_workload_unit.py b/project_workload/models/project_workload_unit.py index b5ed9644..d75a8991 100644 --- a/project_workload/models/project_workload_unit.py +++ b/project_workload/models/project_workload_unit.py @@ -3,7 +3,7 @@ # @author Florian Mounier # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import fields, models +from odoo import api, fields, models class ProjectWorkloadUnit(models.Model): @@ -18,8 +18,21 @@ class ProjectWorkloadUnit(models.Model): ) task_id = fields.Many2one("project.task", "Task", related="workload_id.task_id") project_id = fields.Many2one( - "project.project", "Project", related="workload_id.project_id" + "project.project", + "Project", + related="workload_id.project_id", + store=True, ) + done = fields.Boolean(compute="_compute_done", store=True) + + def is_done(self): + self.ensure_one() + return self.task_id.stage_id.is_closed + + @api.depends("task_id.stage_id.is_closed") + def _compute_done(self): + for record in self: + record.done = record.is_done() def name_get(self): result = [] diff --git a/project_workload/views/menu_view.xml b/project_workload/views/menu_view.xml index 7bf00df1..cd58d3c8 100644 --- a/project_workload/views/menu_view.xml +++ b/project_workload/views/menu_view.xml @@ -9,4 +9,12 @@ groups="project_workload.group_project_workload" /> + + diff --git a/project_workload/views/project_task_workload_unit_view.xml b/project_workload/views/project_task_workload_unit_view.xml new file mode 100644 index 00000000..f5628bda --- /dev/null +++ b/project_workload/views/project_task_workload_unit_view.xml @@ -0,0 +1,66 @@ + + + + + project.workload.unit + + + + + + + + + + + + + + project.workload.unit + + + + + + + + + + + + + + + + + Workload + ir.actions.act_window + project.workload.unit + tree + + [] + {'search_default_my_load': 1, 'search_default_groupby_week': 1} + + + diff --git a/project_workload_timesheet/models/project_workload_unit.py b/project_workload_timesheet/models/project_workload_unit.py index 3a8f39b5..d79f8417 100644 --- a/project_workload_timesheet/models/project_workload_unit.py +++ b/project_workload_timesheet/models/project_workload_unit.py @@ -31,13 +31,16 @@ class ProjectWorkloadUnit(models.Model): compute="_compute_progress", help="The progress of the task", ) - done = fields.Boolean( - "Done", + force_done = fields.Boolean( + "Force Done", ) task_stage_id = fields.Many2one( related="task_id.stage_id", string="Task Stage", readonly=False ) + def is_done(self): + return super().is_done() or self.force_done + @api.depends("timesheet_ids.unit_amount") def _compute_timesheeted_hours(self): for record in self: @@ -82,7 +85,7 @@ def action_timesheet_time(self): return True def action_timesheet_done(self): - self.done = True + self.force_done = True def _get_timesheeting_task(self): # For overrides