[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) <nle@odoo.com>
Signed-off-by: Jorge Pinna Puissant (jpp) <jpp@odoo.com>
This commit is contained in:
Jorge Pinna Puissant
2020-04-30 13:53:17 +00:00
parent 3e81b810aa
commit ed5ab19065
3 changed files with 16 additions and 0 deletions
+7
View File
@@ -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"
+8
View File
@@ -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()
+1
View File
@@ -204,6 +204,7 @@
<field name="hour_to" widget="float_time"/>
<field name="date_from"/>
<field name="date_to"/>
<field name="week_type" readonly="1" force_save="1" groups="base.group_no_one"/>
</tree>
</field>
</record>