From d8f95609eb7dd18109856cfa0ae8fdb1080ce959 Mon Sep 17 00:00:00 2001 From: lul-odoo Date: Thu, 27 Jun 2019 10:23:35 +0200 Subject: [PATCH] [IMP] hr: Add a multi company report printing test Purpose ======= This commit tests some behaviors with multi company mode after changes brought by f847a46. Specification ============= Check that a report printing for several records on different companies: - Works if the context is correctly set, i.e. both companies are in the allowed_company_ids - Doesn't work if the context is not correctly set --- addons/hr/tests/__init__.py | 1 + addons/hr/tests/test_multi_company.py | 35 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 addons/hr/tests/test_multi_company.py diff --git a/addons/hr/tests/__init__.py b/addons/hr/tests/__init__.py index 27d9c2fbb81..c46b7cc336f 100644 --- a/addons/hr/tests/__init__.py +++ b/addons/hr/tests/__init__.py @@ -5,3 +5,4 @@ from . import test_hr_employee from . import test_channel from . import test_hr_flow from . import test_self_user_access +from . import test_multi_company diff --git a/addons/hr/tests/test_multi_company.py b/addons/hr/tests/test_multi_company.py new file mode 100644 index 00000000000..bbe26f9b365 --- /dev/null +++ b/addons/hr/tests/test_multi_company.py @@ -0,0 +1,35 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.tests import Form +from odoo.addons.hr.tests.common import TestHrCommon +from odoo.addons.base.models.qweb import QWebException + + +class TestMultiCompany(TestHrCommon): + + def setUp(self): + super().setUp() + self.company_1 = self.env['res.company'].create({'name': 'Opoo'}) + self.company_2 = self.env['res.company'].create({'name': 'Otoo'}) + self.employees = self.env['hr.employee'].create([ + {'name': 'Bidule', 'company_id': self.company_1.id}, + {'name': 'Machin', 'company_id': self.company_2.id}, + ]) + self.res_users_hr_officer.company_ids = [ + (4, self.company_1.id), + (4, self.company_2.id), + ] + + def test_multi_company_report(self): + content, content_type = self.env.ref('hr.hr_employee_print_badge').sudo(self.res_users_hr_officer).with_context( + allowed_company_ids=[self.company_1.id, self.company_2.id] + ).render_qweb_pdf(res_ids=self.employees.ids) + self.assertIn(b'Bidule', content) + self.assertIn(b'Machin', content) + + def test_single_company_report(self): + with self.assertRaises(QWebException): # CacheMiss followed by AccessError + content, content_type = self.env.ref('hr.hr_employee_print_badge').sudo(self.res_users_hr_officer).with_context( + allowed_company_ids=[self.company_1.id] + ).render_qweb_pdf(res_ids=self.employees.ids)