Files
odoo_source/addons/hr/tests/test_multi_company.py
T
Gorash 9ce5bc8881 [IMP] IrQweb: merge Qweb engine file qweb.py and ir_qweb.py
QWeb is the primary templating engine used by Odoo. It is an XML
templating engine and used mostly to generate XML, HTML fragments and
pages.

To create new XML template, please see :doc:`QWeb Templates documentation
<https://www.odoo.com/documentation/15.0/developer/reference/frontend/qweb.html>`

In **input** you have an XML template giving the corresponding input
etree. Each etree input nodes are used to generate a python function.
This fonction is called and will give the XML **output**.
The ``_compile`` method is responsible to generate the function from the
etree, that function is a python generator that yield one output line at a
time. This generator is consumed by ``_render``. The generated function is
orm cached.

In the graphic below you can see theresume of the call of the methods
performed in the IrQweb class.

    Odoo
     ┗━► _render (returns MarkupSafe)
        ┗━► _compile (returns function)                                        ◄━━━━━━━━━┓
           ┗━► _compile_node (returns code string array)                       ◄━━━━━━━┓ ┃
              ┃  (add technical directives: t-inner-content, t-tag)                    ┃ ┃
              ┣━► _directives_eval_order (defined directive order)                     ┃ ┃
              ┃                                                                        ┃ ┃
              ┣━► _compile_directives                              (recursive) ◄━━━━┓  ┃ ┃
              ┃  ┣━► _compile_directive                                             ┃  ┃ ┃
              ┃  ┃    ┗━► t-if            ━━► _compile_directive_if                ━┫  ┃ ┃
              ┃  ┃    ┗━► t-foreach       ━━► _compile_directive_foreach           ━┫  ┃ ┃
              ┃  ┃    ┗━► t-*             ━━► ...                                  ━┛  ┃ ┃
              ┃  ┃    ┗━► t-inner-content ━━► _compile_directive_inner_content ◄━━━━┓ ━┛ ┃
              ┃  ┃    ┗━► t-tag           ━━► _compile_directive_tag               ━┫    ┃
              ┃  ┃    ┗━► t-call          ━━► _compile_directive_call              ━┫ ━━━┛
              ┃  ┃    ┗━► t-out           ━━► _compile_directive_out           ◄━┓ ━┫
              ┃  ┃    ┗━► t-field         ━━► _compile_directive_field          ━┛  ┃
              ┃  ┃                                                                  ┃
              ┗━━┻━► _compile_static_node                                          ━┛

Part-of: odoo/odoo#81024
2022-02-03 08:09:31 +00:00

42 lines
1.8 KiB
Python

# -*- 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.ir_qweb import QWebException
class TestMultiCompany(TestHrCommon):
@classmethod
def setUpClass(cls):
super().setUpClass()
cls.company_1 = cls.env['res.company'].create({'name': 'Opoo'})
cls.company_2 = cls.env['res.company'].create({'name': 'Otoo'})
cls.employees = cls.env['hr.employee'].create([
{'name': 'Bidule', 'company_id': cls.company_1.id},
{'name': 'Machin', 'company_id': cls.company_2.id},
])
cls.res_users_hr_officer.company_ids = [
(4, cls.company_1.id),
(4, cls.company_2.id),
]
cls.res_users_hr_officer.company_id = cls.company_1.id
# flush and invalidate the cache, otherwise a full cache may prevent
# access rights to be checked
cls.employees.flush()
cls.employees.invalidate_cache()
def test_multi_company_report(self):
content, content_type = self.env.ref('hr.hr_employee_print_badge').with_user(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').with_user(self.res_users_hr_officer).with_company(
self.company_1
)._render_qweb_pdf(res_ids=self.employees.ids)