Browse Source

[IMP] report_py3o: remove obsolete methods

pull/347/head
Laurent Mignon (ACSONE) 6 years ago
parent
commit
bff9e485bb
  1. 2
      report_py3o/controllers/main.py
  2. 22
      report_py3o/models/ir_actions_report.py
  3. 28
      report_py3o/tests/test_report_py3o.py

2
report_py3o/controllers/main.py

@ -44,7 +44,7 @@ class ReportController(main.ReportController):
raise exceptions.HTTPException( raise exceptions.HTTPException(
description='Py3o action report not found for report_name ' description='Py3o action report not found for report_name '
'%s' % reportname) '%s' % reportname)
res, filetype = action_py3o_report.render_py3o(docids, data)
res, filetype = action_py3o_report.render(docids, data)
filename = action_py3o_report.gen_report_download_filename( filename = action_py3o_report.gen_report_download_filename(
docids, data) docids, data)
if not filename.endswith(filetype): if not filename.endswith(filetype):

22
report_py3o/models/ir_actions_report.py

@ -77,14 +77,6 @@ class IrActionsReport(models.Model):
[("report_name", "=", report_name), [("report_name", "=", report_name),
("report_type", "=", report_type)]) ("report_type", "=", report_type)])
@api.model
def render_report(self, res_ids, name, data):
action_py3o_report = self.get_from_report_name(name, "py3o")
if action_py3o_report:
return action_py3o_report.render_py3o(res_ids, data)
return super(IrActionsReport, self).render_report(
res_ids, name, data)
@api.multi @api.multi
def render_py3o(self, res_ids, data): def render_py3o(self, res_ids, data):
self.ensure_one() self.ensure_one()
@ -108,20 +100,6 @@ class IrActionsReport(models.Model):
{'object': obj, 'time': time}) {'object': obj, 'time': time})
return "%s.%s" % (self.name, self.py3o_filetype) return "%s.%s" % (self.name, self.py3o_filetype)
@api.model
def _get_report_from_name(self, report_name):
"""Get the first record of ir.actions.report having the
``report_name`` as value for the field report_name.
"""
res = super(IrActionsReport, self)._get_report_from_name(report_name)
if res:
return res
# maybe a py3o report
context = self.env['res.users'].context_get()
return self.with_context(context).search(
[('report_type', '=', 'py3o'),
('report_name', '=', report_name)], limit=1)
@api.multi @api.multi
def _get_attachments(self, res_ids): def _get_attachments(self, res_ids):
""" Return the report already generated for the given res_ids """ Return the report already generated for the given res_ids

28
report_py3o/tests/test_report_py3o.py

@ -71,21 +71,15 @@ class TestReportPy3o(TransactionCase):
record, result record, result
) or result ) or result
# test the call the the create method inside our custom parser # test the call the the create method inside our custom parser
self.report.render_report(self.env.user.ids,
self.report.report_name,
{})
self.report.render(self.env.user.ids)
self.assertEqual(call_count, patched_pdf.call_count) self.assertEqual(call_count, patched_pdf.call_count)
# generated files no more exists # generated files no more exists
self.assertFalse(os.path.exists(result)) self.assertFalse(os.path.exists(result))
def test_reports(self): def test_reports(self):
res = self.report.render_report(
self.env.user.ids, self.report.report_name, {})
res = self.report.render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
self.report.py3o_filetype = 'pdf' self.report.py3o_filetype = 'pdf'
res = self.report.render_report(
self.env.user.ids, self.report.report_name, {})
self.assertTrue(res)
def test_report_load_from_attachment(self): def test_report_load_from_attachment(self):
self.report.write({"attachment_use": True, self.report.write({"attachment_use": True,
@ -101,8 +95,7 @@ class TestReportPy3o(TransactionCase):
# time we ask the report we received the saved attachment not a newly # time we ask the report we received the saved attachment not a newly
# generated document # generated document
created_attachement.datas = base64.encodestring(b"new content") created_attachement.datas = base64.encodestring(b"new content")
res = self.report.render_report(
self.env.user.ids, self.report.report_name, {})
res = self.report.render(self.env.user.ids)
self.assertEqual((b'new content', self.report.py3o_filetype), res) self.assertEqual((b'new content', self.report.py3o_filetype), res)
def test_report_post_process(self): def test_report_post_process(self):
@ -130,27 +123,23 @@ class TestReportPy3o(TransactionCase):
"odoo.addons.%s" % self.report.module, "odoo.addons.%s" % self.report.module,
tmpl_name) tmpl_name)
self.assertTrue(os.path.exists(flbk_filename)) self.assertTrue(os.path.exists(flbk_filename))
res = self.report.render_report(
self.env.user.ids, self.report.report_name, {})
res = self.report.render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
# The generation fails if the template is not found # The generation fails if the template is not found
self.report.module = False self.report.module = False
with self.assertRaises(TemplateNotFound), self.env.cr.savepoint(): with self.assertRaises(TemplateNotFound), self.env.cr.savepoint():
self.report.render_report(
self.env.user.ids, self.report.report_name, {})
self.report.render(self.env.user.ids)
# the template can also be provided as an abspath if it's root path # the template can also be provided as an abspath if it's root path
# is trusted # is trusted
self.report.py3o_template_fallback = flbk_filename self.report.py3o_template_fallback = flbk_filename
with self.assertRaises(TemplateNotFound): with self.assertRaises(TemplateNotFound):
self.report.render_report(
self.env.user.ids, self.report.report_name, {})
self.report.render(self.env.user.ids)
with temporary_copy(flbk_filename) as tmp_filename: with temporary_copy(flbk_filename) as tmp_filename:
self.report.py3o_template_fallback = tmp_filename self.report.py3o_template_fallback = tmp_filename
tools.config.misc['report_py3o'] = { tools.config.misc['report_py3o'] = {
'root_tmpl_path': os.path.dirname(tmp_filename)} 'root_tmpl_path': os.path.dirname(tmp_filename)}
res = self.report.render_report(
self.env.user.ids, self.report.report_name, {})
res = self.report.render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
# the tempalte can also be provided as a binary field # the tempalte can also be provided as a binary field
@ -164,8 +153,7 @@ class TestReportPy3o(TransactionCase):
'filetype': 'odt'}) 'filetype': 'odt'})
self.report.py3o_template_id = py3o_template self.report.py3o_template_id = py3o_template
self.report.py3o_template_fallback = flbk_filename self.report.py3o_template_fallback = flbk_filename
res = self.report.render_report(
self.env.user.ids, self.report.report_name, {})
res = self.report.render(self.env.user.ids)
self.assertTrue(res) self.assertTrue(res)
@tools.misc.mute_logger('odoo.addons.report_py3o.models.py3o_report') @tools.misc.mute_logger('odoo.addons.report_py3o.models.py3o_report')

Loading…
Cancel
Save