From 8fd9f2ba2409896e66b058cb84f6aa25a7c033ef Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Thu, 15 Feb 2024 17:13:27 +0100 Subject: [PATCH] [IMP] project_workload_timesheet_additions: Adapt unit sheet lines relation for additional loads --- .../models/__init__.py | 1 + .../models/account_analytic_line.py | 38 +++++++++++++++++++ .../models/project_workload_unit.py | 2 + .../views/hr_timesheet_sheet_views.xml | 10 ++++- 4 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 project_workload_timesheet_additions/models/account_analytic_line.py diff --git a/project_workload_timesheet_additions/models/__init__.py b/project_workload_timesheet_additions/models/__init__.py index ef599bd6..bd28cf78 100644 --- a/project_workload_timesheet_additions/models/__init__.py +++ b/project_workload_timesheet_additions/models/__init__.py @@ -1,2 +1,3 @@ +from . import account_analytic_line from . import hr_timesheet_sheet from . import project_workload_unit diff --git a/project_workload_timesheet_additions/models/account_analytic_line.py b/project_workload_timesheet_additions/models/account_analytic_line.py new file mode 100644 index 00000000..e67dbabe --- /dev/null +++ b/project_workload_timesheet_additions/models/account_analytic_line.py @@ -0,0 +1,38 @@ +# Copyright 2024 Akretion (https://www.akretion.com). +# @author Florian Mounier +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import _, api, fields, models +from odoo.exceptions import UserError, ValidationError + + +class AccountAnalyticLine(models.Model): + _inherit = "account.analytic.line" + + workload_unit_id = fields.Many2one( + comodel_name="project.workload.unit", + string="Workload Unit", + readonly=False, + compute="_compute_workload_unit_id", + store=True, + domain="[" + "('week', '=', week), " + "('user_id', '=', user_id), " + "('project_id', '=', project_id), " + "'|', " + "'&', ('additional_task_id', '=', False), ('task_id', '=', task_id), " + "('additional_task_id', '=', task_id)" + "]", + ) + + def _get_available_workload_units_domain(self): + return [ + ("week", "=", self.week), + ("user_id", "=", self.user_id.id), + ("project_id", "=", self.project_id.id), + "|", + "&", + ("additional_task_id", "=", False), + ("task_id", "=", self.task_id.id), + ("additional_task_id", "=", self.task_id.id), + ] diff --git a/project_workload_timesheet_additions/models/project_workload_unit.py b/project_workload_timesheet_additions/models/project_workload_unit.py index c793b2b8..584c2509 100644 --- a/project_workload_timesheet_additions/models/project_workload_unit.py +++ b/project_workload_timesheet_additions/models/project_workload_unit.py @@ -11,11 +11,13 @@ class ProjectWorkloadUnit(models.Model): "project.task.workload.addition", "Additional Task Workload", related="workload_id.additional_workload_id", + store=True, ) additional_task_id = fields.Many2one( "project.task", "Additional Task", related="workload_id.additional_workload_task_id", + store=True, ) def _get_timesheeting_task(self): diff --git a/project_workload_timesheet_additions/views/hr_timesheet_sheet_views.xml b/project_workload_timesheet_additions/views/hr_timesheet_sheet_views.xml index 09c7d84b..a7cc82bc 100644 --- a/project_workload_timesheet_additions/views/hr_timesheet_sheet_views.xml +++ b/project_workload_timesheet_additions/views/hr_timesheet_sheet_views.xml @@ -2,9 +2,15 @@ hr_timesheet.sheet - + - +