diff --git a/report_aeroo/extra_functions.py b/report_aeroo/extra_functions.py index 7aec219..41b5640 100755 --- a/report_aeroo/extra_functions.py +++ b/report_aeroo/extra_functions.py @@ -122,8 +122,7 @@ def format_datetime(report, value: datetime, datetime_format: str): format_datetime = babel.dates.format_datetime( datetime_in_timezone, datetime_format, locale=lang ) - format_datetime = format_datetime.replace("a.m.", "AM").replace( - "p.m.", "PM") + format_datetime = format_datetime.replace("a.m.", "AM").replace("p.m.", "PM") return format_datetime @@ -133,10 +132,12 @@ def format_datetime_now(report, datetime_format: str = None, delta: timedelta = if delta is not None: timestamp += delta - formatted_datetime_now = format_datetime(report, value=timestamp, - datetime_format=datetime_format) - formatted_datetime_now = formatted_datetime_now.replace("a.m.", "AM" - ).replace("p.m.", "PM") + formatted_datetime_now = format_datetime( + report, value=timestamp, datetime_format=datetime_format + ) + formatted_datetime_now = formatted_datetime_now.replace("a.m.", "AM").replace( + "p.m.", "PM" + ) return formatted_datetime_now @@ -151,7 +152,7 @@ def format_decimal(report, amount: float, amount_format="#,##0.00"): """ lang = report._context.get("lang") or "en_US" res = babel.numbers.format_decimal(amount, format=amount_format, locale=lang) - res = res.replace('\u202f', '\xa0') + res = res.replace("\u202f", "\xa0") return res @@ -194,7 +195,7 @@ def format_currency( res = babel.numbers.format_currency( amount, currency.name, format=amount_format, locale=locale ) - res = res.replace('\u202f', '\xa0') + res = res.replace("\u202f", "\xa0") return res diff --git a/report_aeroo/models/ir_actions_report.py b/report_aeroo/models/ir_actions_report.py index db3263c..48aaa97 100644 --- a/report_aeroo/models/ir_actions_report.py +++ b/report_aeroo/models/ir_actions_report.py @@ -23,6 +23,7 @@ from ..namespace import AerooNamespace from ..extra_functions import aeroo_function_registry + _logger = logging.getLogger(__name__) try: @@ -338,8 +339,7 @@ def _render_aeroo(self, doc_ids, data=None, force_output_format=None): """ output_format = force_output_format or self.aeroo_out_format_id.code - if data is None: - data = {} + data = data or {} if len(doc_ids) > 1: return self._render_aeroo_multi(doc_ids, data, output_format) @@ -467,7 +467,7 @@ def _find_aeroo_report_attachment(self, record, output_format): limit=1, ) if attachment: - return base64.decodestring(attachment.datas) + return base64.decodebytes(attachment.datas) return None def _create_aeroo_attachment(self, record, file_data, output_format): @@ -481,7 +481,7 @@ def _create_aeroo_attachment(self, record, file_data, output_format): return self.env["ir.attachment"].create( { "name": filename, - "datas": base64.encodestring(file_data), + "datas": base64.encodebytes(file_data), "res_model": record._name, "res_id": record.id, } @@ -631,12 +631,17 @@ class AerooReportsGeneratedFromListViews(models.Model): _inherit = "ir.actions.report" def _render_aeroo(self, doc_ids, data=None, force_output_format=None): + data = data or {} if self.multi: return self._render_aeroo_from_list_of_records( doc_ids, data, force_output_format ) else: - return super()._render_aeroo(doc_ids, data, force_output_format) + return super()._render_aeroo( + doc_ids=doc_ids, + data=data, + force_output_format=force_output_format, + ) def _render_aeroo_from_list_of_records( self, doc_ids, data=None, force_output_format=None diff --git a/report_aeroo/tests/__init__.py b/report_aeroo/tests/__init__.py index 03a854c..b5aa7a2 100644 --- a/report_aeroo/tests/__init__.py +++ b/report_aeroo/tests/__init__.py @@ -2,13 +2,11 @@ # Copyright 2018 Numigi (tm) and all its contributors (https://bit.ly/numigiens) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from . import ( - test_email_template, - test_extra_functions, - test_load_views, - test_report_aeroo, - test_report_aeroo_access, - test_report_aeroo_company_eval, - test_report_aeroo_lang_eval, - test_report_aeroo_multi -) +from . import test_email_template +from . import test_extra_functions +from . import test_load_views +from . import test_report_aeroo +from . import test_report_aeroo_access +from . import test_report_aeroo_company_eval +from . import test_report_aeroo_lang_eval +from . import test_report_aeroo_multi diff --git a/report_aeroo/tests/test_load_views.py b/report_aeroo/tests/test_load_views.py index bef8746..a3d4763 100644 --- a/report_aeroo/tests/test_load_views.py +++ b/report_aeroo/tests/test_load_views.py @@ -6,7 +6,12 @@ class TestLoadViews(TransactionCase): def test_aeroo_template_data_not_in_result(self): - self.env.ref("report_aeroo.aeroo_sample_report").create_action() - result = self.env["res.partner"].get_views([(None, "tree")], {"toolbar": True}) - actions = result["fields_views"]["tree"]["toolbar"]["print"] - assert "aeroo_template_data" not in actions[0] + simple_report = self.env.ref("report_aeroo.aeroo_sample_report") + simple_report.create_action() + view = self.env.ref("base.view_partner_tree") + result = self.env["res.partner"].get_views( + [(view.id, "list")], {"toolbar": True} + ) + action_reports = result["views"]["list"]["toolbar"]["print"] + report_ids = [report["id"] for report in action_reports] + assert simple_report.id in report_ids diff --git a/report_aeroo/tests/test_report_aeroo.py b/report_aeroo/tests/test_report_aeroo.py index 852ded6..351f2c3 100644 --- a/report_aeroo/tests/test_report_aeroo.py +++ b/report_aeroo/tests/test_report_aeroo.py @@ -70,7 +70,7 @@ def _render_report(self, partners): :param partners: a res.partner recordset """ - self.report.sudo(self.user.id)._render(partners.ids, {}) + self.report._render_aeroo(partners.ids, {}) def _create_report_line(self, lang, company=None): self.report.write( diff --git a/report_aeroo/tests/test_report_aeroo_access.py b/report_aeroo/tests/test_report_aeroo_access.py index 6c65b08..489a126 100644 --- a/report_aeroo/tests/test_report_aeroo_access.py +++ b/report_aeroo/tests/test_report_aeroo_access.py @@ -15,8 +15,8 @@ def setUpClass(cls): cls.user.groups_id |= cls.env.ref("report_aeroo.group_aeroo_manager") def test_report_create(self): - assert self.report.sudo(self.user).copy({}) + assert self.report.with_user(self.user.id).copy({}) def test_report_unlink(self): - self.report.sudo(self.user).unlink() + self.report.with_user(self.user.id).unlink() assert not self.report.exists() diff --git a/report_aeroo/tests/test_report_aeroo_multi.py b/report_aeroo/tests/test_report_aeroo_multi.py index af531e6..5921bb7 100644 --- a/report_aeroo/tests/test_report_aeroo_multi.py +++ b/report_aeroo/tests/test_report_aeroo_multi.py @@ -34,7 +34,7 @@ def _render_report(self, partners): :param partners: a res.partner recordset """ - self.report.sudo(self.env.ref("base.user_demo").id)._render(partners.ids, {}) + self.report.with_user(self.env.ref("base.user_demo").id)._render_aeroo(partners.ids, {}) def test_generate_report_with_pdf_format_and_multiple_records(self): self.report.aeroo_out_format_id = self.env.ref(