diff options
| author | Lucas Lefèvre <lul@odoo.com> | 2019-07-16 13:22:12 +0000 |
|---|---|---|
| committer | Yannick Tivisse <yti@odoo.com> | 2019-07-17 10:25:54 +0000 |
| commit | 2e91d26194f71c70bfc0d9ca4fd3374deda9a768 (patch) | |
| tree | 2cf1d745c924aa917e93359cb9c24541233a4b01 | |
| parent | e2893ce3863ddf858ebee00096e06bbf010ddbc2 (diff) | |
[FIX] project_timesheet_holidays: Allow to create a company
It is currently impossible to create a company.
The reason being that the newly created company is
not yet in context `allowed_company_ids`.
Therefore, every consequent access to a record protected with
a multi company `ir.rule` fails for that company.
Here, the module automatically creates a project in that company
and later read that project to check a constraint.
The read raises an AccessError, hence the company is not created.
On the other hand, a user without project creation access rights
but erp manager could want to create a company. It should work
in that case too, as the project creation is transparent to the
user and the project is archived.
closes odoo/odoo#34920
Signed-off-by: Yannick Tivisse (yti) <yti@odoo.com>
| -rw-r--r-- | addons/project_timesheet_holidays/models/res_company.py | 5 | ||||
| -rw-r--r-- | addons/project_timesheet_holidays/tests/test_timesheet_holidays.py | 13 |
2 files changed, 16 insertions, 2 deletions
diff --git a/addons/project_timesheet_holidays/models/res_company.py b/addons/project_timesheet_holidays/models/res_company.py index 56b59e1b022..58307f874f0 100644 --- a/addons/project_timesheet_holidays/models/res_company.py +++ b/addons/project_timesheet_holidays/models/res_company.py @@ -28,7 +28,10 @@ class Company(models.Model): @api.model def create(self, values): company = super(Company, self).create(values) - company._create_leave_project_task() + # use sudo as the user could have the right to create a company + # but not to create a project. On the other hand, when the company + # is created, it is not in the allowed_company_ids on the env + company.sudo()._create_leave_project_task() return company def _create_leave_project_task(self): diff --git a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py index 25d2da8f00e..e7977266eb5 100644 --- a/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py +++ b/addons/project_timesheet_holidays/tests/test_timesheet_holidays.py @@ -6,7 +6,7 @@ from dateutil.relativedelta import relativedelta from odoo import fields -from odoo.tests import common +from odoo.tests import common, new_test_user from odoo.addons.hr_timesheet.tests.test_timesheet import TestCommonTimesheet @@ -23,6 +23,17 @@ class TestTimesheetHolidaysCreate(common.TransactionCase): self.assertEqual(status.timesheet_project_id, company.leave_timesheet_project_id, 'The default project linked to the status should be the same as the company') self.assertEqual(status.timesheet_task_id, company.leave_timesheet_task_id, 'The default task linked to the status should be the same as the company') + def test_company_create(self): + main_company = self.env.ref('base.main_company') + user = new_test_user(self.env, login='fru', + groups='base.group_user,base.group_erp_manager,base.group_partner_manager', + company_id=main_company.id, + company_ids=[(6, 0, main_company.ids)]) + Company = self.env['res.company'] + Company = Company.with_user(user) + Company = Company.with_context(allowed_company_ids=main_company.ids) + company = Company.create({'name': "Wall Company"}) + self.assertEqual(company.leave_timesheet_project_id.sudo().company_id, company, "It should have created a project for the company") class TestTimesheetHolidays(TestCommonTimesheet): |
