From ed5ab19065767156802fb2a148636ae0c6bbd017 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Wed, 29 Apr 2020 12:59:40 +0000 Subject: [PATCH] [FIX] resource: week_type for new periods In a calendar with 2 weeks mode (odd and even), before this commit, all new created periods (placed in one of the two sections) don't have the week_type field set. This generates a confusion, because a period that should be applied only in odd weeks, for instance, it was applied also in the even weeks. Now, the new periods will have the week_type field set with the week_type of the section where is it. Also, an error message is raised if a period is not in one of the two sections. opw-2239966 closes odoo/odoo#50478 X-original-commit: 33a62118818952872321591e85403b657380128a Signed-off-by: Nicolas Lempereur (nle) Signed-off-by: Jorge Pinna Puissant (jpp) --- addons/resource/i18n/resource.pot | 7 +++++++ addons/resource/models/resource.py | 8 ++++++++ addons/resource/views/resource_views.xml | 1 + 3 files changed, 16 insertions(+) diff --git a/addons/resource/i18n/resource.pot b/addons/resource/i18n/resource.pot index c8b5cd48516..fe21327daab 100644 --- a/addons/resource/i18n/resource.pot +++ b/addons/resource/i18n/resource.pot @@ -242,6 +242,13 @@ msgid "" "record without removing it." msgstr "" +#. module: resource +#: code:addons/resource/models/resource.py:0 +#, python-format +msgid "" +"In a calendar with 2 weeks mode, all periods need to be in the sections." +msgstr "" + #. module: resource #: model_terms:ir.ui.view,arch_db:resource.view_resource_resource_search msgid "Inactive" diff --git a/addons/resource/models/resource.py b/addons/resource/models/resource.py index daf16b47e16..fb79c8819ae 100644 --- a/addons/resource/models/resource.py +++ b/addons/resource/models/resource.py @@ -204,6 +204,14 @@ class ResourceCalendar(models.Model): default.update(name=_('%s (copy)') % (self.name)) return super(ResourceCalendar, self).copy(default) + @api.constrains('attendance_ids') + def _check_attendance_ids(self): + for resource in self: + if (resource.two_weeks_calendar and + resource.attendance_ids.filtered(lambda a: a.display_type == 'line_section') and + not resource.attendance_ids.sorted('sequence')[0].display_type): + raise ValidationError(_("In a calendar with 2 weeks mode, all periods need to be in the sections.")) + @api.depends('two_weeks_calendar') def _compute_two_weeks_explanation(self): today = fields.Date.today() diff --git a/addons/resource/views/resource_views.xml b/addons/resource/views/resource_views.xml index b3c24fb2058..e407f579d10 100644 --- a/addons/resource/views/resource_views.xml +++ b/addons/resource/views/resource_views.xml @@ -204,6 +204,7 @@ +