Skip to content

Commit

Permalink
Merge pull request OCA#8 from acsone/9.0-import_report_py3o
Browse files Browse the repository at this point in the history
9.0 import report py3o
  • Loading branch information
faide committed Oct 4, 2016
2 parents e523ca8 + 31f9301 commit 8b9a824
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 21 deletions.
1 change: 0 additions & 1 deletion report_py3o/demo/.~lock.res_user.odt#

This file was deleted.

4 changes: 3 additions & 1 deletion report_py3o/py3o_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def create_single_pdf(self, cr, uid, ids, data, report_xml, context=None):
"datadict": json.dumps(datadict),
"image_mapping": "{}",
}
if report_xml.py3o_is_local_fusion:
fields['skipfusion'] = '1'
r = requests.post(
report_xml.py3o_server_id.url, data=fields, files=files)
if r.status_code != 200:
Expand All @@ -178,7 +180,7 @@ def create_single_pdf(self, cr, uid, ids, data, report_xml, context=None):
# we do nice chunked reading from the network...
chunk_size = 1024
with NamedTemporaryFile(
suffix=filetype.human_ext,
suffix=filetype,
prefix='py3o-template-'
) as fd:
for chunk in r.iter_content(chunk_size):
Expand Down
34 changes: 23 additions & 11 deletions report_py3o/tests/test_report_py3o.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,26 @@
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)
report = self.env.ref("report_py3o.res_users_report_py3o")
with mock.patch('openerp.addons.report_py3o.py3o_parser.'
'Py3oParser.create_single_pdf') as patched_pdf:
# test the call the the create method inside our custom parser
report.render_report(self.env.user.ids,
report.report_name,
{})
self.assertEqual(1, patched_pdf.call_count)
res = report.render_report(
self.env.user.ids, report.report_name, {})
self.assertTrue(res)
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})
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)
4 changes: 2 additions & 2 deletions report_py3o/views/ir_report.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<openerp>
<odoo>
<data>

<!-- Inherit from base.act_report_xml_view to add py3o-related settings. -->
Expand Down Expand Up @@ -28,4 +28,4 @@
</field>
</record>
</data>
</openerp>
</odoo>
4 changes: 2 additions & 2 deletions report_py3o/views/menu.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>
<menuitem id="py3o_config_menu"
name="Py3o"
parent="report.reporting_menuitem" />
</data>
</openerp>
</odoo>
4 changes: 2 additions & 2 deletions report_py3o/views/py3o_server.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>
<record id="py3o_server_configuration_form_view" model="ir.ui.view">
<field name="name">py3o.server.configuration.form.view</field>
Expand Down Expand Up @@ -39,4 +39,4 @@
parent="py3o_config_menu"
action="py3o_server_configuration_action" />
</data>
</openerp>
</odoo>
4 changes: 2 additions & 2 deletions report_py3o/views/py3o_template.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<odoo>
<data>
<record id="py3o_template_configuration_search_view" model="ir.ui.view">
<field name="name">py3o.template.configuration.search.view</field>
Expand Down Expand Up @@ -51,4 +51,4 @@
parent="py3o_config_menu"
action="py3o_template_configuration_action" />
</data>
</openerp>
</odoo>

0 comments on commit 8b9a824

Please sign in to comment.