From 6421d11e2de16c9574eb9b478cb93048ed9649c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elmeri=20Niemel=C3=A4?= Date: Tue, 2 Feb 2021 08:14:54 +0200 Subject: [PATCH] [MIG] Use safe_eval wrapped time module. Fix deprecation warnings. Co-authored-by: Alexis de Lattre --- report_py3o/controllers/main.py | 3 ++- report_py3o/models/ir_actions_report.py | 5 ++--- report_py3o/models/py3o_report.py | 2 +- report_py3o/tests/test_report_py3o.py | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/report_py3o/controllers/main.py b/report_py3o/controllers/main.py index 08deed20..c26fee9f 100644 --- a/report_py3o/controllers/main.py +++ b/report_py3o/controllers/main.py @@ -3,7 +3,8 @@ import json import mimetypes -from werkzeug import exceptions, url_decode +from werkzeug import exceptions +from werkzeug.urls import url_decode from odoo.http import request, route from odoo.tools import html_escape diff --git a/report_py3o/models/ir_actions_report.py b/report_py3o/models/ir_actions_report.py index 2e5ff7da..cbc072e9 100644 --- a/report_py3o/models/ir_actions_report.py +++ b/report_py3o/models/ir_actions_report.py @@ -2,12 +2,11 @@ # Copyright 2018 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). import logging -import time from odoo import _, api, fields, models from odoo.exceptions import ValidationError from odoo.tools.misc import find_in_path -from odoo.tools.safe_eval import safe_eval +from odoo.tools.safe_eval import safe_eval, time logger = logging.getLogger(__name__) @@ -180,7 +179,7 @@ class IrActionsReport(models.Model): report = self.get_from_report_name(self.report_name, self.report_type) if report.print_report_name and not len(res_ids) > 1: obj = self.env[self.model].browse(res_ids) - return safe_eval(report.print_report_name, {"object": obj,}) + return safe_eval(report.print_report_name, {"object": obj, "time": time}) return "{}.{}".format(self.name, self.py3o_filetype) def _get_attachments(self, res_ids): diff --git a/report_py3o/models/py3o_report.py b/report_py3o/models/py3o_report.py index a4c9015a..c204431e 100644 --- a/report_py3o/models/py3o_report.py +++ b/report_py3o/models/py3o_report.py @@ -279,7 +279,7 @@ class Py3oReport(models.TransientModel): self.ensure_one() attachment = existing_reports_attachment.get(model_instance.id) if attachment and self.ir_actions_report_id.attachment_use: - content = base64.decodestring(attachment.datas) + content = base64.b64decode(attachment.datas) report_file = tempfile.mktemp("." + self.ir_actions_report_id.py3o_filetype) with open(report_file, "wb") as f: f.write(content) diff --git a/report_py3o/tests/test_report_py3o.py b/report_py3o/tests/test_report_py3o.py index 294c79fe..629e9c63 100644 --- a/report_py3o/tests/test_report_py3o.py +++ b/report_py3o/tests/test_report_py3o.py @@ -57,7 +57,7 @@ class TestReportPy3o(TransactionCase): with self.assertRaises(ValidationError) as e: self.report.py3o_filetype = False self.assertEqual( - e.exception.name, "Field 'Output Format' is required for Py3O report" + e.exception.args[0], "Field 'Output Format' is required for Py3O report" ) def _render_patched(self, result_text="test result", call_count=1): @@ -121,7 +121,7 @@ class TestReportPy3o(TransactionCase): # put a new content into tha attachement and check that the next # time we ask the report we received the saved attachment not a newly # generated document - created_attachement.datas = base64.encodestring(b"new content") + created_attachement.datas = base64.b64encode(b"new content") res = self.report._render(self.env.user.ids) self.assertEqual((b"new content", self.report.py3o_filetype), res)