Browse Source

[FIX] report_py3o: fix exception when report must be saved as attachement

The mehtod  must be called with a list of ids not with a list of browse records
14.0-report-py3o-pr-506
Laurent Mignon (ACSONE) 8 years ago
committed by default
parent
commit
689bdc0d23
  1. 2
      report_py3o/models/py3o_report.py
  2. 29
      report_py3o/tests/test_report_py3o.py

2
report_py3o/models/py3o_report.py

@ -321,7 +321,7 @@ class Py3oReport(models.TransientModel):
model_instances = self.env[self.ir_actions_report_xml_id.model].browse( model_instances = self.env[self.ir_actions_report_xml_id.model].browse(
res_ids) res_ids)
save_in_attachment = self._check_attachment_use( 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 = [] reports_path = []
for model_instance in model_instances: for model_instance in model_instances:
reports_path.append( reports_path.append(

29
report_py3o/tests/test_report_py3o.py

@ -2,6 +2,7 @@
# Copyright 2016 ACSONE SA/NV # Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).).
from base64 import b64decode
import mock import mock
import os import os
import pkg_resources import pkg_resources
@ -88,6 +89,34 @@ class TestReportPy3o(TransactionCase):
self.env.user.ids, report.report_name, {}) self.env.user.ids, report.report_name, {})
self.assertEqual(('test result', 'pdf'), res) 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): def test_report_template_configs(self):
report = self.env.ref("report_py3o.res_users_report_py3o") report = self.env.ref("report_py3o.res_users_report_py3o")
# the demo template is specified with a relative path in in the module # the demo template is specified with a relative path in in the module

Loading…
Cancel
Save