Browse Source

Port report_py3o to Odoo v10

14.0-report-py3o-pr-506
Alexis de Lattre 8 years ago
committed by default
parent
commit
5c2982ed33
  1. 29
      report_py3o/models/ir_actions_report_xml.py
  2. 2
      report_py3o/models/py3o_server.py
  3. 2
      report_py3o/models/py3o_template.py
  4. 29
      report_py3o/py3o_parser.py
  5. 8
      report_py3o/tests/test_report_py3o.py
  6. 12
      report_py3o/views/ir_report.xml

29
report_py3o/models/ir_actions_report_xml.py

@ -3,10 +3,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import os
import logging
from openerp import api, fields, models, SUPERUSER_ID, _
from openerp.report.interface import report_int
from openerp.exceptions import ValidationError
from openerp import addons
from odoo import api, fields, models, SUPERUSER_ID, _
from odoo.report.interface import report_int
from odoo.exceptions import ValidationError
from odoo import addons
from ..py3o_parser import Py3oParser
logger = logging.getLogger(__name__)
@ -85,11 +85,12 @@ class IrActionsReportXml(models.Model):
))
report_type = fields.Selection(selection_add=[('py3o', "Py3o")])
@api.cr
def _lookup_report(self, cr, name):
@api.model_cr
def _lookup_report(self, name):
"""Look up a report definition.
"""
# START section copied from odoo/addons/base/ir/ir_actions.py
# with small adaptations
# First lookup in the deprecated place, because if the report
# definition has not been updated, it is more likely the correct
# definition is there. Only reports with custom parser
@ -99,14 +100,12 @@ class IrActionsReportXml(models.Model):
if not isinstance(new_report, Py3oParser):
new_report = None
else:
report_data = self.search_read(
cr, SUPERUSER_ID,
[("report_name", "=", name),
("report_type", "=", "py3o")],
['parser', 'model', 'report_name', 'report_rml', 'header'],
limit=1)
self._cr.execute(
"SELECT * FROM ir_act_report_xml "
"WHERE report_name=%s AND report_type=%s", (name, 'py3o'))
report_data = self._cr.dictfetchone()
# END section copied from odoo/addons/base/ir/ir_actions.py
if report_data:
report_data = report_data[0]
kwargs = {}
if report_data['parser']:
kwargs['parser'] = getattr(addons, report_data['parser'])
@ -125,4 +124,4 @@ class IrActionsReportXml(models.Model):
if new_report:
return new_report
else:
return super(IrActionsReportXml, self)._lookup_report(cr, name)
return super(IrActionsReportXml, self)._lookup_report(name)

2
report_py3o/models/py3o_server.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2013 XCG Consulting (http://odoo.consulting)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models
from odoo import fields, models
class Py3oServer(models.Model):

2
report_py3o/models/py3o_template.py

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Copyright 2013 XCG Consulting (http://odoo.consulting)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import fields, models
from odoo import fields, models
class Py3oTemplate(models.Model):

29
report_py3o/py3o_parser.py

@ -9,10 +9,9 @@ import sys
from base64 import b64decode
import requests
from tempfile import NamedTemporaryFile
from openerp import _
from openerp import exceptions
from openerp.report.report_sxw import report_sxw
from openerp import registry
from odoo import api, _
from odoo import exceptions
from odoo.report.report_sxw import report_sxw
import logging
logger = logging.getLogger(__name__)
@ -77,12 +76,12 @@ class Py3oParser(report_sxw):
will fallback to the template file referenced in the report definition.
@param report_obj: a recordset representing the report defintion
@type report_obj: openerp.model.recordset instance
@type report_obj: odoo.model.recordset instance
@returns: string or buffer containing the template data
@raises: TemplateNotFound which is a subclass of
openerp.exceptions.DeferredException
odoo.exceptions.DeferredException
"""
tmpl_data = None
@ -99,7 +98,7 @@ class Py3oParser(report_sxw):
if report_obj.module:
# if the default is defined
flbk_filename = pkg_resources.resource_filename(
"openerp.addons.%s" % report_obj.module,
"odoo.addons.%s" % report_obj.module,
tmpl_name,
)
elif os.path.isabs(tmpl_name):
@ -203,22 +202,16 @@ class Py3oParser(report_sxw):
def create(self, cr, uid, ids, data, context=None):
""" Override this function to handle our py3o report
"""
pool = registry(cr.dbname)
ir_action_report_obj = pool['ir.actions.report.xml']
report_xml_ids = ir_action_report_obj.search(
cr, uid, [('report_name', '=', self.name[7:])], context=context
)
if not report_xml_ids:
env = api.Environment(cr, uid, context)
report_xmls = env['ir.actions.report.xml'].search(
[('report_name', '=', self.name[7:])])
if not report_xmls:
return super(Py3oParser, self).create(
cr, uid, ids, data, context=context
)
report_xml = ir_action_report_obj.browse(
cr, uid, report_xml_ids[0], context=context
)
result = self.create_source_pdf(
cr, uid, ids, data, report_xml, context
cr, uid, ids, data, report_xmls[0], context
)
if not result:

8
report_py3o/tests/test_report_py3o.py

@ -8,8 +8,8 @@ import pkg_resources
from py3o.formats import Formats
from openerp.tests.common import TransactionCase
from openerp.exceptions import ValidationError
from odoo.tests.common import TransactionCase
from odoo.exceptions import ValidationError
from ..py3o_parser import TemplateNotFound
from base64 import b64encode
@ -57,7 +57,7 @@ class TestReportPy3o(TransactionCase):
def test_reports(self):
report = self.env.ref("report_py3o.res_users_report_py3o")
with mock.patch('openerp.addons.report_py3o.py3o_parser.'
with mock.patch('odoo.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,
@ -86,7 +86,7 @@ class TestReportPy3o(TransactionCase):
# path
tmpl_name = report.py3o_template_fallback
flbk_filename = pkg_resources.resource_filename(
"openerp.addons.%s" % report.module,
"odoo.addons.%s" % report.module,
tmpl_name)
self.assertTrue(os.path.exists(flbk_filename))
res = report.render_report(

12
report_py3o/views/ir_report.xml

@ -28,4 +28,16 @@
</field>
</record>
<record id="act_report_xml_search_view" model="ir.ui.view">
<field name="name">py3o_report_search_view</field>
<field name="model">ir.actions.report.xml</field>
<field name="inherit_id" ref="base.act_report_xml_search_view"/>
<field name="arch" type="xml">
<field name="model" position="after">
<filter name="py3o" string="Py3o Reports"
domain="[('report_type', '=', 'py3o')]"/>
</field>
</field>
</record>
</odoo>
Loading…
Cancel
Save