diff --git a/report_py3o/__openerp__.py b/report_py3o/__openerp__.py
index b5b8d052..e86cc6fa 100644
--- a/report_py3o/__openerp__.py
+++ b/report_py3o/__openerp__.py
@@ -24,11 +24,11 @@ The py3o.template package is required; install it with:
},
'data': [
'security/ir.model.access.csv',
-
'views/menu.xml',
'views/py3o_template.xml',
'views/py3o_server.xml',
'views/ir_report.xml',
+ 'demo/report_py3o.xml',
],
'installable': True,
}
diff --git a/report_py3o/demo/.~lock.res_user.odt# b/report_py3o/demo/.~lock.res_user.odt#
new file mode 100644
index 00000000..3f8e53eb
--- /dev/null
+++ b/report_py3o/demo/.~lock.res_user.odt#
@@ -0,0 +1 @@
+,lmi,nbacsonelmi,04.10.2016 15:56,file:///home/lmi/.config/libreoffice/4;
\ No newline at end of file
diff --git a/report_py3o/demo/report_py3o.xml b/report_py3o/demo/report_py3o.xml
new file mode 100644
index 00000000..b57342f1
--- /dev/null
+++ b/report_py3o/demo/report_py3o.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+ Py3o Demo Report
+ ir.actions.report.xml
+ res.users
+ py3o_user_info
+ py3o
+ odt
+
+ odt
+ report_py3o
+ demo/res_user.odt
+
+
+
+
+
+ res.users
+ Py3o Demo Report
+
+
+
+
diff --git a/report_py3o/demo/res_user.odt b/report_py3o/demo/res_user.odt
new file mode 100644
index 00000000..f0d66bb8
Binary files /dev/null and b/report_py3o/demo/res_user.odt differ
diff --git a/report_py3o/i18n/fr.po b/report_py3o/i18n/fr.po
index 39653c67..171e2e55 100644
--- a/report_py3o/i18n/fr.po
+++ b/report_py3o/i18n/fr.po
@@ -102,7 +102,7 @@ msgid "No Py3o server configuration found"
msgstr "Pas de configuration trouvée du serveur Py3o"
#. module: report_py3o
-#: field:ir.actions.report.xml,py3o_fusion_filetype:0
+#: field:ir.actions.report.xml,py3o_filetype:0
msgid "Output Format"
msgstr "Format de sortie"
diff --git a/report_py3o/models/ir_report.py b/report_py3o/models/ir_report.py
index 7c9686c7..418b7105 100644
--- a/report_py3o/models/ir_report.py
+++ b/report_py3o/models/ir_report.py
@@ -19,17 +19,17 @@ class ReportXml(models.Model):
_inherit = 'ir.actions.report.xml'
@api.one
- @api.constrains("py3o_fusion_filetype", "report_type")
- def _check_py3o_fusion_filetype(self):
- if self.report_type == "py3o" and not self.py3o_fusion_filetype:
+ @api.constrains("py3o_filetype", "report_type")
+ def _check_py3o_filetype(self):
+ if self.report_type == "py3o" and not self.py3o_filetype:
raise ValidationError(
"Field 'Output Format' is required for Py3O report")
@api.one
@api.constrains("py3o_is_local_fusion", "py3o_server_id",
- "py3o_fusion_filetype")
+ "py3o_filetype")
def _check_py3o_server_id(self):
- is_native = Formats().get_format(self.py3o_fusion_filetype)
+ is_native = Formats().get_format(self.py3o_filetype)
if ((not is_native or not self.py3o_is_local_fusion) and
not self.py3o_server_id):
raise ValidationError(
@@ -37,7 +37,7 @@ class ReportXml(models.Model):
"Please specify a Fusion Server")
@api.model
- def _get_py3o_fusion_filetypes(self):
+ def _get_py3o_filetypes(self):
formats = Formats()
names = formats.get_known_format_names()
selections = []
@@ -48,8 +48,8 @@ class ReportXml(models.Model):
selections.append((name, description))
return selections
- py3o_fusion_filetype = fields.Selection(
- selection="_get_py3o_fusion_filetypes",
+ py3o_filetype = fields.Selection(
+ selection="_get_py3o_filetypes",
string="Output Format")
py3o_template_id = fields.Many2one(
'py3o.template',
diff --git a/report_py3o/py3o_parser.py b/report_py3o/py3o_parser.py
index f3e9c687..b3f4380d 100644
--- a/report_py3o/py3o_parser.py
+++ b/report_py3o/py3o_parser.py
@@ -143,26 +143,27 @@ class Py3oParser(report_sxw):
localcontext = parser_instance.localcontext
if report_xml.py3o_is_local_fusion:
template.render(localcontext)
- input = out_stream.getvalue()
+ in_stream = out_stream
+ datadict = {}
else:
expressions = template.get_all_user_python_expression()
py_expression = template.convert_py3o_to_python_ast(expressions)
convertor = Py3oConvertor()
data_struct = convertor(py_expression)
- input = data_struct.render(localcontext)
+ datadict = data_struct.render(localcontext)
- filetype = report_xml.py3o_fusion_filetype
+ filetype = report_xml.py3o_filetype
is_native = Formats().get_format(filetype).native
if is_native:
- res = input
+ res = out_stream.getvalue()
else: # Call py3o.server to render the template in the desired format
in_stream.seek(0)
files = {
'tmpl_file': in_stream,
}
fields = {
- "targetformat": filetype.fusion_ext,
- "datadict": json.dumps(input),
+ "targetformat": filetype,
+ "datadict": json.dumps(datadict),
"image_mapping": "{}",
}
r = requests.post(
diff --git a/report_py3o/tests/__init__.py b/report_py3o/tests/__init__.py
new file mode 100644
index 00000000..13bc3247
--- /dev/null
+++ b/report_py3o/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_report_py3o
diff --git a/report_py3o/tests/test_report_py3o.py b/report_py3o/tests/test_report_py3o.py
new file mode 100644
index 00000000..c8afa04a
--- /dev/null
+++ b/report_py3o/tests/test_report_py3o.py
@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+# Copyright 2016 ACSONE SA/NV
+# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).).
+
+
+import mock
+
+from openerp.tests.common import TransactionCase
+import openerp.tests
+
+
+@openerp.tests.common.at_install(False)
+@openerp.tests.common.post_install(True)
+class TestReportPy3o(TransactionCase):
+
+ def test_reports(self):
+ domain = [('report_type', '=', 'py3o'),
+ ('report_name', '=', 'py3o_user_info')]
+ reports = self.env['ir.actions.report.xml'].search(domain)
+ self.assertEqual(1, len(reports))
+ for r in reports:
+ with mock.patch('openerp.addons.report_py3o.py3o_parser.'
+ 'Py3oParser.create_single_pdf') as patched_pdf:
+ r.render_report(self.env.user.ids,
+ r.report_name,
+ {})
+ self.assertEqual(1, patched_pdf.call_count)
diff --git a/report_py3o/views/ir_report.xml b/report_py3o/views/ir_report.xml
index e3469464..f06b4468 100644
--- a/report_py3o/views/ir_report.xml
+++ b/report_py3o/views/ir_report.xml
@@ -14,7 +14,7 @@
attrs="{'invisible': [('report_type', '!=', 'py3o')]}">
-
+