diff --git a/addons/resource/i18n/resource.pot b/addons/resource/i18n/resource.pot index 87fafcd0229..8f17492dbc3 100644 --- a/addons/resource/i18n/resource.pot +++ b/addons/resource/i18n/resource.pot @@ -272,13 +272,6 @@ msgid "" "Time without removing it." msgstr "" -#. module: resource -#. odoo-python -#: code:addons/resource/models/resource_calendar.py:0 -#, python-format -msgid "Impossible to switch calendar type for the default company schedule." -msgstr "" - #. module: resource #. odoo-python #: code:addons/resource/models/resource_calendar.py:0 diff --git a/addons/resource/models/resource_calendar.py b/addons/resource/models/resource_calendar.py index 0e31849f657..8e4f1a20e0a 100644 --- a/addons/resource/models/resource_calendar.py +++ b/addons/resource/models/resource_calendar.py @@ -14,7 +14,7 @@ from pytz import timezone, utc from odoo import api, fields, models, _ from odoo.addons.base.models.res_partner import _tz_get -from odoo.exceptions import ValidationError, UserError +from odoo.exceptions import ValidationError from odoo.osv import expression from odoo.tools.float_utils import float_round @@ -45,7 +45,7 @@ class ResourceCalendar(models.Model): company_id = res.get('company_id', self.env.company.id) company = self.env['res.company'].browse(company_id) company_attendance_ids = company.resource_calendar_id.attendance_ids - if company_attendance_ids: + if not company.resource_calendar_id.two_weeks_calendar and company_attendance_ids: res['attendance_ids'] = [ (0, 0, { 'name': attendance.name, @@ -184,9 +184,6 @@ class ResourceCalendar(models.Model): return float_round(hour_count / float(number_of_days), precision_digits=2) def switch_calendar_type(self): - if self == self.env.company.resource_calendar_id: - raise UserError(_('Impossible to switch calendar type for the default company schedule.')) - if not self.two_weeks_calendar: self.attendance_ids.unlink() self.attendance_ids = [ diff --git a/addons/test_resource/tests/common.py b/addons/test_resource/tests/common.py index ee2dee6dff7..94fd46fa9e6 100644 --- a/addons/test_resource/tests/common.py +++ b/addons/test_resource/tests/common.py @@ -82,3 +82,22 @@ class TestResourceCommon(TransactionCase): 'name': 'Paul', 'resource_calendar_id': cls.calendar_paul.id, }) + + cls.two_weeks_resource = cls._define_calendar_2_weeks( + 'Two weeks resource', + [ + (0, 0, 0, '0', 'line_section', 0), + (8, 16, 0, '0', False, 1), + (8, 16, 1, '0', False, 2), + (8, 16, 2, '0', False, 3), + (8, 16, 3, '0', False, 4), + (8, 16, 4, '0', False, 5), + (0, 0, 0, '1', 'line_section', 10), + (8, 16, 0, '1', False, 11), + (8, 16, 1, '1', False, 12), + (8, 16, 2, '1', False, 13), + (8, 16, 3, '1', False, 14), + (8, 16, 4, '1', False, 15) + ], + 'Europe/Brussels' + ) diff --git a/addons/test_resource/tests/test_resource.py b/addons/test_resource/tests/test_resource.py index 03cb1e1f311..ad33358d5a6 100644 --- a/addons/test_resource/tests/test_resource.py +++ b/addons/test_resource/tests/test_resource.py @@ -1320,3 +1320,21 @@ class TestResource(TestResourceCommon): self.assertEqual(31, sum_work_intervals_jules, "Sum of the work intervals for the calendar of jules should be Wodd:15h+Wpair:16h = 31h") sum_work_intervals_patel = sum_intervals(calendars_intervals[self.calendar_patel.id]) self.assertEqual(49, sum_work_intervals_patel, "Sum of the work intervals for the calendar of patel should be 14+35h = 49h") + + def test_switch_two_weeks_resource(self): + """ + Check that it is possible to switch the company's default calendar + """ + self.env.company.resource_calendar_id = self.two_weeks_resource + company_resource = self.env.company.resource_calendar_id + # Switch two times to be sure to test both cases + company_resource.switch_calendar_type() + company_resource.switch_calendar_type() + + def test_create_company_using_two_weeks_resource(self): + """ + Check that we can create a new company + if the default company calendar is two weeks + """ + self.env.company.resource_calendar_id = self.two_weeks_resource + self.env['res.company'].create({'name': 'New Company'})