From 8d6eb345a898b86b494a9a8e94edb067fc694ac7 Mon Sep 17 00:00:00 2001 From: Robin Keunen Date: Fri, 2 Feb 2024 13:54:45 +0100 Subject: [PATCH 1/2] [REF] resource_work_time_from_contracts: remove readonly This line has the side effect of issuing a warning for all models inheriting resource.mixin and setting defaults to resource_calendar_id. The readonly was introduced to prevent modifications by the user since the modules computes it. It is however to relevant since the field is hidden (readonly parameter only affects the views). --- resource_work_time_from_contracts/models/resource_mixin.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/resource_work_time_from_contracts/models/resource_mixin.py b/resource_work_time_from_contracts/models/resource_mixin.py index 442869f61..42f6fc3cb 100644 --- a/resource_work_time_from_contracts/models/resource_mixin.py +++ b/resource_work_time_from_contracts/models/resource_mixin.py @@ -16,8 +16,7 @@ class ResourceMixin(models.AbstractModel): _inherit = "resource.mixin" - # make this field read-only. - resource_calendar_id = fields.Many2one("resource.calendar", readonly=True) + resource_calendar_id = fields.Many2one("resource.calendar") def list_work_time_per_day( self, From 704797674391a3c871dbca4a1a36c0c5498039fb Mon Sep 17 00:00:00 2001 From: Robin Keunen Date: Fri, 2 Feb 2024 14:17:19 +0100 Subject: [PATCH 2/2] [REF] resource_work_time_from_contracts: add fixme comments --- .../models/resource_calendar_leaves.py | 3 +++ resource_work_time_from_contracts/models/resource_mixin.py | 4 +--- resource_work_time_from_contracts/models/resource_resource.py | 4 ++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/resource_work_time_from_contracts/models/resource_calendar_leaves.py b/resource_work_time_from_contracts/models/resource_calendar_leaves.py index a2483761b..25437cb17 100644 --- a/resource_work_time_from_contracts/models/resource_calendar_leaves.py +++ b/resource_work_time_from_contracts/models/resource_calendar_leaves.py @@ -13,6 +13,9 @@ class ResourceCalendarLeaves(models.Model): # leaves for all resources are defined in the same resource calendar, # which is needed to compute working hours while taking leaves into # account. + # fixme A readonly related field without an inverse method should not have a + # default value, as it does not make sense. + # cf odoo/odoo/fields.py:626 calendar_id = fields.Many2one( "resource.calendar", related="resource_id.calendar_id", diff --git a/resource_work_time_from_contracts/models/resource_mixin.py b/resource_work_time_from_contracts/models/resource_mixin.py index 42f6fc3cb..e2daf482b 100644 --- a/resource_work_time_from_contracts/models/resource_mixin.py +++ b/resource_work_time_from_contracts/models/resource_mixin.py @@ -6,7 +6,7 @@ from pytz import timezone, utc -from odoo import fields, models +from odoo import models from odoo.tools import float_utils from odoo.addons.resource.models.resource import ROUNDING_FACTOR @@ -16,8 +16,6 @@ class ResourceMixin(models.AbstractModel): _inherit = "resource.mixin" - resource_calendar_id = fields.Many2one("resource.calendar") - def list_work_time_per_day( self, from_datetime, diff --git a/resource_work_time_from_contracts/models/resource_resource.py b/resource_work_time_from_contracts/models/resource_resource.py index 134f6934a..6870149ec 100644 --- a/resource_work_time_from_contracts/models/resource_resource.py +++ b/resource_work_time_from_contracts/models/resource_resource.py @@ -9,6 +9,10 @@ class ResourceResource(models.Model): _inherit = "resource.resource" # force this field to be equal to the resource_calendar_id of the company. + # fixme A readonly related field without an inverse method should not have a + # default value, as it does not make sense. + # cf odoo/odoo/fields.py:626 + calendar_id = fields.Many2one( "resource.calendar", related="company_id.resource_calendar_id",