diff --git a/report_py3o/README.rst b/report_py3o/README.rst index 141c33cd..58731bec 100644 --- a/report_py3o/README.rst +++ b/report_py3o/README.rst @@ -207,7 +207,9 @@ Contributors ------------ * Florent Aide (`XCG Consulting `_) -* Laurent Mignon (Acsone) +* Laurent Mignon , +* Alexis de Lattre , + Maintainer ---------- diff --git a/report_py3o/__manifest__.py b/report_py3o/__manifest__.py index 90761d21..6d6522f8 100644 --- a/report_py3o/__manifest__.py +++ b/report_py3o/__manifest__.py @@ -8,7 +8,9 @@ 'version': '10.0.1.0.0', 'category': 'Reporting', 'license': 'AGPL-3', - 'author': 'XCG Consulting,Odoo Community Association (OCA)', + 'author': 'XCG Consulting,' + 'ACSONE SA/NV,' + 'Odoo Community Association (OCA)', 'website': 'http://odoo.consulting/', 'depends': ['report'], 'external_dependencies': { diff --git a/report_py3o/models/__init__.py b/report_py3o/models/__init__.py index 425cb3d9..863d037d 100644 --- a/report_py3o/models/__init__.py +++ b/report_py3o/models/__init__.py @@ -1,4 +1,5 @@ from . import ir_actions_report_xml from . import py3o_template from . import py3o_server +from . import report from . import py3o_report diff --git a/report_py3o/models/py3o_report.py b/report_py3o/models/py3o_report.py index ccebbcb8..5aa5d574 100644 --- a/report_py3o/models/py3o_report.py +++ b/report_py3o/models/py3o_report.py @@ -172,20 +172,6 @@ class Py3oReport(models.TransientModel): self._extend_parser_context(context_instance, report_xml) return context_instance.localcontext - @api.model - def _get_report_from_name(self, report_name): - """Get the first record of ir.actions.report.xml having the - ``report_name`` as value for the field report_name. - """ - res = super(Py3oReport, self)._get_report_from_name(report_name) - if res: - return res - # maybe a py3o reprot - report_obj = self.env['ir.actions.report.xml'] - return report_obj.search( - [('report_type', '=', 'py3o'), - ('report_name', '=', report_name)]) - @api.model def _postprocess_report(self, report_path, res_id, save_in_attachment): if save_in_attachment.get(res_id): @@ -321,7 +307,7 @@ class Py3oReport(models.TransientModel): model_instances = self.env[self.ir_actions_report_xml_id.model].browse( res_ids) save_in_attachment = self._check_attachment_use( - model_instances, self.ir_actions_report_xml_id) or {} + res_ids, self.ir_actions_report_xml_id) or {} reports_path = [] for model_instance in model_instances: reports_path.append( diff --git a/report_py3o/models/report.py b/report_py3o/models/report.py new file mode 100644 index 00000000..0666861c --- /dev/null +++ b/report_py3o/models/report.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Akretion (http://www.akretion.com/) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import api, models + + +class Report(models.Model): + + _inherit = 'report' + + @api.model + def _get_report_from_name(self, report_name): + """Get the first record of ir.actions.report.xml having the + ``report_name`` as value for the field report_name. + """ + res = super(Report, self)._get_report_from_name(report_name) + if res: + return res + # maybe a py3o report + report_obj = self.env['ir.actions.report.xml'] + context = self.env['res.users'].context_get() + return report_obj.with_context(context).search( + [('report_type', '=', 'py3o'), + ('report_name', '=', report_name)], limit=1) diff --git a/report_py3o/tests/test_report_py3o.py b/report_py3o/tests/test_report_py3o.py index 70e4a513..131cb563 100644 --- a/report_py3o/tests/test_report_py3o.py +++ b/report_py3o/tests/test_report_py3o.py @@ -2,6 +2,7 @@ # Copyright 2016 ACSONE SA/NV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).). +from base64 import b64decode import mock import os import pkg_resources @@ -88,6 +89,34 @@ class TestReportPy3o(TransactionCase): self.env.user.ids, report.report_name, {}) self.assertEqual(('test result', 'pdf'), res) + def test_report_post_process(self): + """ + By default the post_process method is in charge to save the + generated report into an ir.attachment if requested. + """ + report = self.env.ref("report_py3o.res_users_report_py3o") + report.attachment = "object.name + '.txt'" + py3o_server = self.env['py3o.server'].create({"url": "http://dummy"}) + # check the call to the fusion server + report.write({"py3o_filetype": "pdf", + "py3o_server_id": py3o_server.id}) + ir_attachment = self.env['ir.attachment'] + attachements = ir_attachment.search([(1, '=', 1)]) + with mock.patch('requests.post') as patched_post: + magick_response = mock.MagicMock() + magick_response.status_code = 200 + patched_post.return_value = magick_response + magick_response.iter_content.return_value = "test result" + res = report.render_report( + self.env.user.ids, report.report_name, {}) + self.assertEqual(('test result', 'pdf'), res) + attachements = ir_attachment.search([(1, '=', 1)]) - attachements + self.assertEqual(1, len(attachements.ids)) + self.assertEqual(self.env.user.name + '.txt', attachements.name) + self.assertEqual(self.env.user._name, attachements.res_model) + self.assertEqual(self.env.user.id, attachements.res_id) + self.assertEqual('test result', b64decode(attachements.datas)) + def test_report_template_configs(self): report = self.env.ref("report_py3o.res_users_report_py3o") # the demo template is specified with a relative path in in the module