Skip to content

Commit

Permalink
Merge pull request #1 from leemannd/14.0-mig-report_py3o
Browse files Browse the repository at this point in the history
run pre-commit
  • Loading branch information
elmeriniemela committed Nov 23, 2021
2 parents 0ddf462 + dcfd5c1 commit debb900
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion report_py3o/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"category": "Reporting",
"license": "AGPL-3",
"author": "XCG Consulting," "ACSONE SA/NV," "Odoo Community Association (OCA)",
"website": "http://odoo.consulting/",
"website": "https://github.com/OCA/reporting-engine",
"depends": ["web"],
"external_dependencies": {"python": ["py3o.template", "py3o.formats", "PyPDF2"]},
"data": [
Expand Down
3 changes: 1 addition & 2 deletions report_py3o/models/_py3o_parser_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,11 @@ def _format_date(self, value, lang_code=False, date_format=False):
self._env, value, lang_code=lang_code, date_format=date_format
)

def _format_datetime(self, value, tz=False, dt_format='medium', lang_code=False):
def _format_datetime(self, value, tz=False, dt_format="medium", lang_code=False):
return misc.format_datetime(
self._env, value, tz=tz, dt_format=dt_format, lang_code=lang_code
)


def _old_format_lang(
self,
value,
Expand Down
10 changes: 4 additions & 6 deletions report_py3o/models/ir_actions_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class IrActionsReport(models.Model):
""" Inherit from ir.actions.report to allow customizing the template
"""Inherit from ir.actions.report to allow customizing the template
file. The user cam chose a template from a list.
The list is configurable in the configuration tab, see py3o_template.py
"""
Expand Down Expand Up @@ -49,7 +49,7 @@ def _get_py3o_filetypes(self):
report_type = fields.Selection(
selection_add=[("py3o", "py3o")],
ondelete={
'py3o': 'cascade',
"py3o": "cascade",
},
)

Expand Down Expand Up @@ -173,8 +173,7 @@ def _render_py3o(self, res_ids, data):
)

def gen_report_download_filename(self, res_ids, data):
"""Override this function to change the name of the downloaded report
"""
"""Override this function to change the name of the downloaded report"""
self.ensure_one()
report = self.get_from_report_name(self.report_name, self.report_type)
if report.print_report_name and not len(res_ids) > 1:
Expand All @@ -183,8 +182,7 @@ def gen_report_download_filename(self, res_ids, data):
return "{}.{}".format(self.name, self.py3o_filetype)

def _get_attachments(self, res_ids):
""" Return the report already generated for the given res_ids
"""
"""Return the report already generated for the given res_ids"""
self.ensure_one()
save_in_attachment = {}
if res_ids:
Expand Down
22 changes: 10 additions & 12 deletions report_py3o/models/py3o_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
except ImportError:
logger.debug("Cannot import py3o.formats")
try:
from PyPDF2 import PdfFileWriter, PdfFileReader
from PyPDF2 import PdfFileReader, PdfFileWriter
except ImportError:
logger.debug("Cannot import PyPDF2")

Expand Down Expand Up @@ -83,8 +83,7 @@ class Py3oReport(models.TransientModel):
)

def _is_valid_template_path(self, path):
""" Check if the path is a trusted path for py3o templates.
"""
"""Check if the path is a trusted path for py3o templates."""
real_path = os.path.realpath(path)
root_path = tools.config.get_misc("report_py3o", "root_tmpl_path")
if not root_path:
Expand All @@ -105,8 +104,7 @@ def _is_valid_template_path(self, path):
return is_valid

def _is_valid_template_filename(self, filename):
""" Check if the filename can be used as py3o template
"""
"""Check if the filename can be used as py3o template"""
if filename and os.path.isfile(filename):
fname, ext = os.path.splitext(filename)
ext = ext.replace(".", "")
Expand All @@ -120,7 +118,7 @@ def _is_valid_template_filename(self, filename):
return False

def _get_template_from_path(self, tmpl_name):
""" Return the template from the path to root of the module if specied
"""Return the template from the path to root of the module if specied
or an absolute path on your server
"""
if not tmpl_name:
Expand Down Expand Up @@ -201,12 +199,13 @@ def _postprocess_report(self, model_instance, result_path):
# consumption...
# ... but odoo wants the whole data in memory anyways :)
buffer = BytesIO(f.read())
self.ir_actions_report_id._postprocess_pdf_report(model_instance, buffer)
self.ir_actions_report_id._postprocess_pdf_report(
model_instance, buffer
)
return result_path

def _create_single_report(self, model_instance, data):
""" This function to generate our py3o report
"""
"""This function to generate our py3o report"""
self.ensure_one()
result_fd, result_path = tempfile.mkstemp(
suffix=".ods", prefix="p3o.report.tmp."
Expand Down Expand Up @@ -306,7 +305,7 @@ def _zip_results(self, reports_path):

@api.model
def _merge_pdf(self, reports_path):
""" Merge PDF files into one.
"""Merge PDF files into one.
:param reports_path: list of path of pdf files
:returns: path of the merged pdf
Expand Down Expand Up @@ -344,8 +343,7 @@ def _cleanup_tempfiles(self, temporary_files):
logger.error("Error when trying to remove file %s" % temporary_file)

def create_report(self, res_ids, data):
""" Override this function to handle our py3o report
"""
"""Override this function to handle our py3o report"""
model_instances = self.env[self.ir_actions_report_id.model].browse(res_ids)
reports_path = []
if len(res_ids) > 1 and self.ir_actions_report_id.py3o_multi_in_one:
Expand Down
6 changes: 3 additions & 3 deletions report_py3o/static/src/js/py3oactionmanager.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
/* Copyright 2017-2018 ACSONE SA/NV
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
odoo.define("report_py3o.report", function(require) {
odoo.define("report_py3o.report", function (require) {
"use strict";

var ActionManager = require("web.ActionManager");

ActionManager.include({
_executeReportAction: function(action, options) {
_executeReportAction: function (action, options) {
// Py3o reports
if ("report_type" in action && action.report_type === "py3o") {
return this._triggerDownload(action, options, "py3o");
}
return this._super.apply(this, arguments);
},

_makeReportUrls: function(action) {
_makeReportUrls: function (action) {
var reportUrls = this._super.apply(this, arguments);
reportUrls.py3o = "/report/py3o/" + action.report_name;
// We may have to build a query string with `action.data`. It's the place
Expand Down
2 changes: 1 addition & 1 deletion report_py3o/tests/test_report_py3o.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import tempfile
from base64 import b64decode, b64encode
from contextlib import contextmanager

from unittest import mock

import pkg_resources
from PyPDF2 import PdfFileWriter
from PyPDF2.pdf import PageObject
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# generated from manifests external_dependencies
lxml
py3o.formats
py3o.template
PyPDF2
xlrd
xlsxwriter
1 change: 1 addition & 0 deletions setup/report_py3o/odoo/addons/report_py3o
6 changes: 6 additions & 0 deletions setup/report_py3o/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit debb900

Please sign in to comment.