Browse Source

Add simple tests and fix call to fusion server

14.0-report-py3o-pr-506
Laurent Mignon 8 years ago
committed by default
parent
commit
86203b3921
  1. 2
      report_py3o/__openerp__.py
  2. 1
      report_py3o/demo/.~lock.res_user.odt#
  3. 28
      report_py3o/demo/report_py3o.xml
  4. BIN
      report_py3o/demo/res_user.odt
  5. 2
      report_py3o/i18n/fr.po
  6. 16
      report_py3o/models/ir_report.py
  7. 13
      report_py3o/py3o_parser.py
  8. 1
      report_py3o/tests/__init__.py
  9. 27
      report_py3o/tests/test_report_py3o.py
  10. 2
      report_py3o/views/ir_report.xml

2
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,
}

1
report_py3o/demo/.~lock.res_user.odt#

@ -0,0 +1 @@
,lmi,nbacsonelmi,04.10.2016 15:56,file:///home/lmi/.config/libreoffice/4;

28
report_py3o/demo/report_py3o.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright 2016 ACSONE SA/NV
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="res_users_report_py3o" model="ir.actions.report.xml">
<field name="name">Py3o Demo Report</field>
<field name="type">ir.actions.report.xml</field>
<field name="model">res.users</field>
<field name="report_name">py3o_user_info</field>
<field name="report_type">py3o</field>
<field name="py3o_filetype">odt</field>
<field name="py3o_is_local_fusion" eval="1"/>
<field name="py3o_filetype">odt</field>
<field name="module">report_py3o</field>
<field name="py3o_template_fallback">demo/res_user.odt</field>
</record>
<record id="res_users_report_py3o_print_action" model="ir.values">
<field eval="'action'" name="key" />
<field eval="'client_print_multi'" name="key2" />
<field name="model">res.users</field>
<field name="name">Py3o Demo Report</field>
<field eval="'ir.actions.report.xml,'+str(res_users_report_py3o)" name="value" />
</record>
</odoo>

BIN
report_py3o/demo/res_user.odt

2
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"

16
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',

13
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(

1
report_py3o/tests/__init__.py

@ -0,0 +1 @@
from . import test_report_py3o

27
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)

2
report_py3o/views/ir_report.xml

@ -14,7 +14,7 @@
attrs="{'invisible': [('report_type', '!=', 'py3o')]}">
<group>
<field name="py3o_fusion_filetype" />
<field name="py3o_filetype" />
<field name="py3o_is_local_fusion"/>
<field name="py3o_server_id" />
<field name="py3o_template_id" />

Loading…
Cancel
Save