[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>
This commit is contained in:
committed by
Yannick Tivisse
parent
e2893ce386
commit
2e91d26194
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user