Browse Source

[14.0][MIG] report_py3o: Migration to 14.0

14.0-report-py3o-pr-506
Elmeri Niemelä 4 years ago
committed by default
parent
commit
a1cdcc780e
  1. 13
      report_py3o/README.rst
  2. 2
      report_py3o/__manifest__.py
  3. 2
      report_py3o/controllers/main.py
  4. 11
      report_py3o/models/ir_actions_report.py
  5. 2
      report_py3o/models/py3o_report.py
  6. 1
      report_py3o/security/ir.model.access.csv
  7. 4
      report_py3o/static/description/index.html
  8. 28
      report_py3o/tests/test_report_py3o.py

13
report_py3o/README.rst

@ -14,16 +14,16 @@ Py3o Report Engine
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3 :alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github
:target: https://github.com/OCA/reporting-engine/tree/13.0/report_py3o
:target: https://github.com/OCA/reporting-engine/tree/14.0/report_py3o
:alt: OCA/reporting-engine :alt: OCA/reporting-engine
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/reporting-engine-13-0/reporting-engine-13-0-report_py3o
:target: https://translation.odoo-community.org/projects/reporting-engine-14.0/reporting-engine-14.0-report_py3o
:alt: Translate me on Weblate :alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/143/13.0
:target: https://runbot.odoo-community.org/runbot/143/14.0
:alt: Try me on Runbot :alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|
The py3o reporting engine is a reporting engine for Odoo based on `Libreoffice <http://www.libreoffice.org/>`_: The py3o reporting engine is a reporting engine for Odoo based on `Libreoffice <http://www.libreoffice.org/>`_:
@ -203,7 +203,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_. Bugs are tracked on `GitHub Issues <https://github.com/OCA/reporting-engine/issues>`_.
In case of trouble, please check there if your issue has already been reported. In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_py3o%0Aversion:%2013.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/reporting-engine/issues/new?body=module:%20report_py3o%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Do not contact contributors directly about support or help with technical issues. Do not contact contributors directly about support or help with technical issues.
@ -225,6 +225,7 @@ Contributors
* Guewen Baconnier <guewen.baconnier@camptocamp.com> * Guewen Baconnier <guewen.baconnier@camptocamp.com>
* Omar Castiñeira <omar@comunitea.com> * Omar Castiñeira <omar@comunitea.com>
* Holger Brunn <hbrunn@therp.nl> * Holger Brunn <hbrunn@therp.nl>
* Elmeri Niemelä <elmeri.niemela@sprintit.fi>
Maintainers Maintainers
~~~~~~~~~~~ ~~~~~~~~~~~
@ -239,6 +240,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use. promote its widespread use.
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/13.0/report_py3o>`_ project on GitHub.
This module is part of the `OCA/reporting-engine <https://github.com/OCA/reporting-engine/tree/14.0/report_py3o>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

2
report_py3o/__manifest__.py

@ -4,7 +4,7 @@
"name": "Py3o Report Engine", "name": "Py3o Report Engine",
"summary": "Reporting engine based on Libreoffice (ODT -> ODT, " "summary": "Reporting engine based on Libreoffice (ODT -> ODT, "
"ODT -> PDF, ODT -> DOC, ODT -> DOCX, ODS -> ODS, etc.)", "ODT -> PDF, ODT -> DOC, ODT -> DOCX, ODS -> ODS, etc.)",
"version": "13.0.1.0.0",
"version": "14.0.1.0.0",
"category": "Reporting", "category": "Reporting",
"license": "AGPL-3", "license": "AGPL-3",
"author": "XCG Consulting," "ACSONE SA/NV," "Odoo Community Association (OCA)", "author": "XCG Consulting," "ACSONE SA/NV," "Odoo Community Association (OCA)",

2
report_py3o/controllers/main.py

@ -43,7 +43,7 @@ class ReportController(main.ReportController):
description="Py3o action report not found for report_name " description="Py3o action report not found for report_name "
"%s" % reportname "%s" % reportname
) )
res, filetype = action_py3o_report.render(docids, data)
res, filetype = action_py3o_report._render(docids, data)
filename = action_py3o_report.gen_report_download_filename(docids, data) filename = action_py3o_report.gen_report_download_filename(docids, data)
if not filename.endswith(filetype): if not filename.endswith(filetype):
filename = "{}.{}".format(filename, filetype) filename = "{}.{}".format(filename, filetype)

11
report_py3o/models/ir_actions_report.py

@ -47,7 +47,13 @@ class IrActionsReport(models.Model):
selections.append((name, description)) selections.append((name, description))
return selections return selections
report_type = fields.Selection(selection_add=[("py3o", "py3o")])
report_type = fields.Selection(
selection_add=[("py3o", "py3o")],
ondelete={
'py3o': 'cascade',
},
)
py3o_filetype = fields.Selection( py3o_filetype = fields.Selection(
selection="_get_py3o_filetypes", string="Output Format" selection="_get_py3o_filetypes", string="Output Format"
) )
@ -65,7 +71,6 @@ class IrActionsReport(models.Model):
"or an absolute path on your server." "or an absolute path on your server."
), ),
) )
report_type = fields.Selection(selection_add=[("py3o", "Py3o")])
py3o_multi_in_one = fields.Boolean( py3o_multi_in_one = fields.Boolean(
string="Multiple Records in a Single Report", string="Multiple Records in a Single Report",
help="If you execute a report on several records, " help="If you execute a report on several records, "
@ -155,7 +160,7 @@ class IrActionsReport(models.Model):
[("report_name", "=", report_name), ("report_type", "=", report_type)] [("report_name", "=", report_name), ("report_type", "=", report_type)]
) )
def render_py3o(self, res_ids, data):
def _render_py3o(self, res_ids, data):
self.ensure_one() self.ensure_one()
if self.report_type != "py3o": if self.report_type != "py3o":
raise RuntimeError( raise RuntimeError(

2
report_py3o/models/py3o_report.py

@ -196,7 +196,7 @@ class Py3oReport(models.TransientModel):
# consumption... # consumption...
# ... but odoo wants the whole data in memory anyways :) # ... but odoo wants the whole data in memory anyways :)
buffer = BytesIO(f.read()) 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 return result_path
def _create_single_report(self, model_instance, data): def _create_single_report(self, model_instance, data):

1
report_py3o/security/ir.model.access.csv

@ -1,3 +1,4 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_py3o_template_admin,access_py3o_template_admin,model_py3o_template,base.group_no_one,1,1,1,1 access_py3o_template_admin,access_py3o_template_admin,model_py3o_template,base.group_no_one,1,1,1,1
access_py3o_template_user,access_py3o_template_user,model_py3o_template,base.group_user,1,0,0,0 access_py3o_template_user,access_py3o_template_user,model_py3o_template,base.group_user,1,0,0,0
access_py3o_report_user,access_py3o_report_user,model_py3o_report,base.group_user,1,1,1,1

4
report_py3o/static/description/index.html

@ -367,7 +367,7 @@ ul.auto-toc {
!! This file is generated by oca-gen-addon-readme !! !! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !! !! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! --> !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/13.0/report_py3o"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-13-0/reporting-engine-13-0-report_py3o"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/13.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/14.0/report_py3o"><img alt="OCA/reporting-engine" src="https://img.shields.io/badge/github-OCA%2Freporting--engine-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/reporting-engine-14.0/reporting-engine-14.0-report_py3o"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/143/14.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
<p>The py3o reporting engine is a reporting engine for Odoo based on <a class="reference external" href="http://www.libreoffice.org/">Libreoffice</a>:</p> <p>The py3o reporting engine is a reporting engine for Odoo based on <a class="reference external" href="http://www.libreoffice.org/">Libreoffice</a>:</p>
<ul class="simple"> <ul class="simple">
<li>the report is created with Libreoffice (ODT or ODS),</li> <li>the report is created with Libreoffice (ODT or ODS),</li>
@ -576,7 +576,7 @@ If you spotted it first, help us smashing it by providing a detailed and welcome
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and mission is to support the collaborative development of Odoo features and
promote its widespread use.</p> promote its widespread use.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/13.0/report_py3o">OCA/reporting-engine</a> project on GitHub.</p>
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/reporting-engine/tree/14.0/report_py3o">OCA/reporting-engine</a> project on GitHub.</p>
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p> <p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
</div> </div>
</div> </div>

28
report_py3o/tests/test_report_py3o.py

@ -9,7 +9,7 @@ import tempfile
from base64 import b64decode, b64encode from base64 import b64decode, b64encode
from contextlib import contextmanager from contextlib import contextmanager
import mock
from unittest import mock
import pkg_resources import pkg_resources
from PyPDF2 import PdfFileWriter from PyPDF2 import PdfFileWriter
from PyPDF2.pdf import PageObject from PyPDF2.pdf import PageObject
@ -46,7 +46,7 @@ def temporary_copy(path):
class TestReportPy3o(TransactionCase): class TestReportPy3o(TransactionCase):
def setUp(self): def setUp(self):
super(TestReportPy3o, self).setUp() super(TestReportPy3o, self).setUp()
self.env.user.image = PNG
self.env.user.image_1920 = PNG
self.report = self.env.ref("report_py3o.res_users_report_py3o") self.report = self.env.ref("report_py3o.res_users_report_py3o")
self.py3o_report = self.env["py3o.report"].create( self.py3o_report = self.env["py3o.report"].create(
{"ir_actions_report_id": self.report.id} {"ir_actions_report_id": self.report.id}
@ -74,13 +74,13 @@ class TestReportPy3o(TransactionCase):
or result or result
) )
# test the call the the create method inside our custom parser # test the call the the create method inside our custom parser
self.report.render(self.env.user.ids)
self.report._render(self.env.user.ids)
self.assertEqual(call_count, patched_pdf.call_count) self.assertEqual(call_count, patched_pdf.call_count)
# generated files no more exists # generated files no more exists
self.assertFalse(os.path.exists(result)) self.assertFalse(os.path.exists(result))
def test_reports(self): def test_reports(self):
res = self.report.render(self.env.user.ids)
res = self.report._render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
def test_reports_merge_zip(self): def test_reports_merge_zip(self):
@ -93,7 +93,7 @@ class TestReportPy3o(TransactionCase):
py3o_report.__class__, "_zip_results" py3o_report.__class__, "_zip_results"
) as patched_zip_results: ) as patched_zip_results:
patched_zip_results.side_effect = _zip_results patched_zip_results.side_effect = _zip_results
content, filetype = self.report.render(users.ids)
content, filetype = self.report._render(users.ids)
self.assertEqual(1, patched_zip_results.call_count) self.assertEqual(1, patched_zip_results.call_count)
self.assertEqual(filetype, "zip") self.assertEqual(filetype, "zip")
@ -122,7 +122,7 @@ class TestReportPy3o(TransactionCase):
# time we ask the report we received the saved attachment not a newly # time we ask the report we received the saved attachment not a newly
# generated document # generated document
created_attachement.datas = base64.encodestring(b"new content") created_attachement.datas = base64.encodestring(b"new content")
res = self.report.render(self.env.user.ids)
res = self.report._render(self.env.user.ids)
self.assertEqual((b"new content", self.report.py3o_filetype), res) self.assertEqual((b"new content", self.report.py3o_filetype), res)
def test_report_post_process(self): def test_report_post_process(self):
@ -150,24 +150,24 @@ class TestReportPy3o(TransactionCase):
"odoo.addons.%s" % self.report.module, tmpl_name "odoo.addons.%s" % self.report.module, tmpl_name
) )
self.assertTrue(os.path.exists(flbk_filename)) self.assertTrue(os.path.exists(flbk_filename))
res = self.report.render(self.env.user.ids)
res = self.report._render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
# The generation fails if the template is not found # The generation fails if the template is not found
self.report.module = False self.report.module = False
with self.assertRaises(TemplateNotFound), self.env.cr.savepoint(): with self.assertRaises(TemplateNotFound), self.env.cr.savepoint():
self.report.render(self.env.user.ids)
self.report._render(self.env.user.ids)
# the template can also be provided as an abspath if it's root path # the template can also be provided as an abspath if it's root path
# is trusted # is trusted
self.report.py3o_template_fallback = flbk_filename self.report.py3o_template_fallback = flbk_filename
with self.assertRaises(TemplateNotFound): with self.assertRaises(TemplateNotFound):
self.report.render(self.env.user.ids)
self.report._render(self.env.user.ids)
with temporary_copy(flbk_filename) as tmp_filename: with temporary_copy(flbk_filename) as tmp_filename:
self.report.py3o_template_fallback = tmp_filename self.report.py3o_template_fallback = tmp_filename
tools.config.misc["report_py3o"] = { tools.config.misc["report_py3o"] = {
"root_tmpl_path": os.path.dirname(tmp_filename) "root_tmpl_path": os.path.dirname(tmp_filename)
} }
res = self.report.render(self.env.user.ids)
res = self.report._render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
# the tempalte can also be provided as a binary field # the tempalte can also be provided as a binary field
@ -184,7 +184,7 @@ class TestReportPy3o(TransactionCase):
) )
self.report.py3o_template_id = py3o_template self.report.py3o_template_id = py3o_template
self.report.py3o_template_fallback = flbk_filename self.report.py3o_template_fallback = flbk_filename
res = self.report.render(self.env.user.ids)
res = self.report._render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
@tools.misc.mute_logger("odoo.addons.report_py3o.models.py3o_report") @tools.misc.mute_logger("odoo.addons.report_py3o.models.py3o_report")
@ -240,7 +240,7 @@ class TestReportPy3o(TransactionCase):
self.assertFalse(self.report.lo_bin_path) self.assertFalse(self.report.lo_bin_path)
self.assertFalse(self.report.is_py3o_report_not_available) self.assertFalse(self.report.is_py3o_report_not_available)
self.assertFalse(self.report.msg_py3o_report_not_available) self.assertFalse(self.report.msg_py3o_report_not_available)
res = self.report.render(self.env.user.ids)
res = self.report._render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
# The report should become unavailable for an non native output format # The report should become unavailable for an non native output format
@ -249,7 +249,7 @@ class TestReportPy3o(TransactionCase):
self.assertTrue(self.report.is_py3o_report_not_available) self.assertTrue(self.report.is_py3o_report_not_available)
self.assertTrue(self.report.msg_py3o_report_not_available) self.assertTrue(self.report.msg_py3o_report_not_available)
with self.assertRaises(RuntimeError): with self.assertRaises(RuntimeError):
self.report.render(self.env.user.ids)
self.report._render(self.env.user.ids)
# if we reset the wrong path, everything should work # if we reset the wrong path, everything should work
self.env["ir.config_parameter"].set_param( self.env["ir.config_parameter"].set_param(
@ -260,5 +260,5 @@ class TestReportPy3o(TransactionCase):
self.assertFalse(self.report.is_py3o_native_format) self.assertFalse(self.report.is_py3o_native_format)
self.assertFalse(self.report.is_py3o_report_not_available) self.assertFalse(self.report.is_py3o_report_not_available)
self.assertFalse(self.report.msg_py3o_report_not_available) self.assertFalse(self.report.msg_py3o_report_not_available)
res = self.report.render(self.env.user.ids)
res = self.report._render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
Loading…
Cancel
Save