Files
odoo_source/addons/hr/tests/test_multi_company.py
T
Romain Derie 88b19cfa92 [FIX] base, mail: _render_qweb_pdf should return a bytes-like object
`result` might be a Markup object (eg during tests) or a bytes-like object.

Step to reproduce: click on "Send by Mail" on a SO -> Traceback

Step to reproduce (2):
- Install website_sale
- Add something to the cart
- Go through checkout and click on Pay Now
- Crash, 500 error page, as this step is trying to generate the SO PDF to send
  by mail to the customer, which tries to encode a bytes-like object.

```
AttributeError: 'bytes' object has no attribute 'encode'
```

But if you do that flow during a test, eg
```
./odoo-bin -d mydb --test-tags=.test_02_admin_checkout
```
You have a Markup object, thus you had to encode it.

Now, even during test, we return a bytes-like object.

Related to #68299

Community: https://github.com/odoo/odoo/pull/75377
Enterprise: https://github.com/odoo/enterprise/pull/20449
Part-of: odoo/odoo#75377
2021-08-26 10:21:28 +00:00

37 lines
1.6 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.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),
]
self.res_users_hr_officer.company_id = self.company_1.id
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)