run pre-commit

pull/445/head^2
Denis Leemann 2021-11-23 15:56:02 +01:00
parent 0ddf462e04
commit dcfd5c1ec4
9 changed files with 29 additions and 25 deletions

View File

@ -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": [

View File

@ -92,12 +92,11 @@ class Py3oParserContext(object):
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,

View File

@ -49,7 +49,7 @@ class IrActionsReport(models.Model):
report_type = fields.Selection(
selection_add=[("py3o", "py3o")],
ondelete={
'py3o': 'cascade',
"py3o": "cascade",
},
)
@ -173,8 +173,7 @@ class IrActionsReport(models.Model):
)
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:
@ -183,8 +182,7 @@ class IrActionsReport(models.Model):
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:

View File

@ -35,7 +35,7 @@ try:
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")
@ -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:
@ -105,8 +104,7 @@ class Py3oReport(models.TransientModel):
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(".", "")
@ -201,12 +199,13 @@ class Py3oReport(models.TransientModel):
# 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."
@ -344,8 +343,7 @@ class Py3oReport(models.TransientModel):
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:

View File

@ -8,8 +8,8 @@ import shutil
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

View File

@ -1,5 +1,7 @@
# generated from manifests external_dependencies
lxml
py3o.formats
py3o.template
PyPDF2
xlrd
xlsxwriter

View File

@ -0,0 +1 @@
../../../../report_py3o

View File

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)