Skip to content

Commit c4731ee

Browse files
committed
[MIG] report_py3o: Migration to 19.0
1 parent 0a57387 commit c4731ee

5 files changed

Lines changed: 55 additions & 22 deletions

File tree

report_py3o/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"name": "Py3o Report Engine",
55
"summary": "Reporting engine based on Libreoffice (ODT -> ODT, "
66
"ODT -> PDF, ODT -> DOC, ODT -> DOCX, ODS -> ODS, etc.)",
7-
"version": "18.0.1.0.2",
7+
"version": "19.0.1.0.0",
88
"category": "Reporting",
99
"license": "AGPL-3",
1010
"author": "XCG Consulting, ACSONE SA/NV, Odoo Community Association (OCA)",

report_py3o/static/src/js/py3oactionservice.esm.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
/** @odoo-module **/
2-
31
import {download} from "@web/core/network/download";
42
import {registry} from "@web/core/registry";
53

report_py3o/tests/test_report_py3o.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@
2626

2727
from odoo.addons.base.tests.test_mimetypes import PNG
2828

29-
from ..models._py3o_parser_context import format_multiline_value
3029
from ..models.ir_actions_report import PY3O_CONVERSION_COMMAND_PARAMETER
31-
from ..models.py3o_report import TemplateNotFound
30+
from ..wizard._py3o_parser_context import format_multiline_value
31+
from ..wizard.py3o_report import TemplateNotFound
3232

3333
logger = logging.getLogger(__name__)
3434

@@ -91,8 +91,17 @@ def test_reports(self):
9191

9292
def test_reports_merge_zip(self):
9393
self.report.py3o_filetype = "odt"
94-
users = self.env["res.users"].search([])
95-
self.assertTrue(len(users) > 0)
94+
users = self.env["res.users"].search([], limit=2)
95+
if len(users) < 2:
96+
users |= self.env["res.users"].create(
97+
{
98+
"name": "Test User 2",
99+
"login": f"test_user_2_{self.env.cr.dbname}",
100+
"email": f"test_user_2_{self.env.cr.dbname}@example.com",
101+
}
102+
)
103+
self.assertGreaterEqual(len(users), 2)
104+
users.write({"image_1920": PNG})
96105
py3o_report = self.env["py3o.report"]
97106
_zip_results = self.py3o_report._zip_results
98107
with mock.patch.object(
@@ -147,7 +156,7 @@ def test_report_post_process(self):
147156
self.assertEqual(self.env.user.id, attachements.res_id)
148157
self.assertEqual(b"test result", b64decode(attachements.datas))
149158

150-
@tools.misc.mute_logger("odoo.addons.report_py3o.models.py3o_report")
159+
@tools.misc.mute_logger("odoo.addons.report_py3o.wizard.py3o_report")
151160
def test_report_template_configs(self):
152161
# the demo template is specified with a relative path in in the module
153162
# path
@@ -169,9 +178,9 @@ def test_report_template_configs(self):
169178
self.report._render(self.report.id, self.env.user.ids)
170179
with temporary_copy(flbk_filename) as tmp_filename:
171180
self.report.py3o_template_fallback = tmp_filename
172-
tools.config.misc["report_py3o"] = {
173-
"root_tmpl_path": os.path.realpath(os.path.dirname(tmp_filename))
174-
}
181+
tools.config["root_tmpl_path"] = os.path.realpath(
182+
os.path.dirname(tmp_filename)
183+
)
175184
res = self.report._render(self.report.id, self.env.user.ids)
176185
self.assertTrue(res)
177186

@@ -192,7 +201,7 @@ def test_report_template_configs(self):
192201
res = self.report._render(self.report.id, self.env.user.ids)
193202
self.assertTrue(res)
194203

195-
@tools.misc.mute_logger("odoo.addons.report_py3o.models.py3o_report")
204+
@tools.misc.mute_logger("odoo.addons.report_py3o.wizard.py3o_report")
196205
def test_report_template_fallback_validity(self):
197206
tmpl_name = self.report.py3o_template_fallback
198207
with as_file(files(f"odoo.addons.{self.report.module}")) as _asf:

report_py3o/views/py3o_template.xml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,11 @@
77
<search>
88
<field name="name" />
99
<field name="filetype" />
10-
<group string="Group By" name="groupby">
11-
<filter
12-
name="filetype_groupby"
13-
string="File Type"
14-
context="{'group_by': 'filetype'}"
15-
/>
16-
</group>
10+
<filter
11+
name="filetype_groupby"
12+
string="File Type"
13+
context="{'group_by': 'filetype'}"
14+
/>
1715
</search>
1816
</field>
1917
</record>

report_py3o/wizard/py3o_report.py

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,40 @@
99
import tempfile
1010
import warnings
1111
from base64 import b64decode
12+
from configparser import ConfigParser
1213
from contextlib import closing
1314
from importlib.resources import files
1415
from io import BytesIO
1516
from zipfile import ZIP_DEFLATED, ZipFile
1617

17-
from odoo import api, fields, models, tools
18+
from odoo import api, fields, models
1819
from odoo.exceptions import AccessError
20+
from odoo.tools import config
1921
from odoo.tools.safe_eval import safe_eval, time
2022

2123
from ._py3o_parser_context import Py3oParserContext
2224

2325
logger = logging.getLogger(__name__)
2426

27+
try:
28+
# Preferred source when available: structured [report_py3o] section provided
29+
# by OCA's server_environment addon.
30+
from odoo.addons.server_environment import serv_config
31+
32+
if serv_config.has_section("report_py3o"):
33+
report_py3o_config = serv_config["report_py3o"]
34+
else:
35+
report_py3o_config = {}
36+
except ImportError:
37+
# No server_environment: try to read a [report_py3o] section from odoo.conf
38+
report_py3o_config = {}
39+
cfg_path = config.get("config")
40+
if cfg_path:
41+
cp = ConfigParser(interpolation=None)
42+
cp.read(cfg_path)
43+
if cp.has_section("report_py3o"):
44+
report_py3o_config = dict(cp["report_py3o"])
45+
2546
try:
2647
# workaround for https://github.com/edgewall/genshi/issues/15
2748
# that makes runbot build red because of the DeprecationWarning
@@ -86,7 +107,11 @@ class Py3oReport(models.TransientModel):
86107
def _is_valid_template_path(self, path):
87108
"""Check if the path is a trusted path for py3o templates."""
88109
real_path = os.path.realpath(path)
89-
root_path = tools.config.get_misc("report_py3o", "root_tmpl_path")
110+
root_path = report_py3o_config.get("root_tmpl_path") or config.get(
111+
"root_tmpl_path"
112+
)
113+
if root_path:
114+
root_path = os.path.realpath(root_path.strip()).rstrip(os.path.sep)
90115
if not root_path:
91116
logger.warning(
92117
"You must provide a root template path into odoo.cfg to be "
@@ -95,7 +120,10 @@ def _is_valid_template_path(self, path):
95120
real_path,
96121
)
97122
return False
98-
is_valid = real_path.startswith(root_path + os.path.sep)
123+
try:
124+
is_valid = os.path.commonpath([root_path, real_path]) == root_path
125+
except ValueError:
126+
is_valid = False
99127
if not is_valid:
100128
logger.warning(
101129
"Py3o template path is not valid. %s is not a child of root path %s",

0 commit comments

Comments
 (0)