[MIG] report_xml: Migration to 11.0
parent
24dedbc75d
commit
1b10c9f366
|
@ -1,5 +1,5 @@
|
||||||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||||
:alt: License: AGPL-3
|
:alt: License: AGPL-3
|
||||||
|
|
||||||
===========
|
===========
|
||||||
|
@ -84,11 +84,4 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||||
mission is to support the collaborative development of Odoo features and
|
mission is to support the collaborative development of Odoo features and
|
||||||
promote its widespread use.
|
promote its widespread use.
|
||||||
|
|
||||||
To contribute to this module, please visit http://odoo-community.org.
|
To contribute to this module, please visit https://odoo-community.org.
|
||||||
|
|
||||||
|
|
||||||
.. _custom report: https://www.odoo.com/documentation/8.0/reference/reports.html#custom-reports
|
|
||||||
.. _instructions to create reports: https://www.odoo.com/documentation/8.0/reference/reports.html
|
|
||||||
.. _reporting-engine: https://github.com/OCA/reporting-engine
|
|
||||||
.. _sample module: https://github.com/OCA/reporting-engine/tree/8.0/report_xml_sample
|
|
||||||
.. _lxml: http://lxml.de/
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
from . import controllers
|
from . import controllers
|
||||||
from . import models
|
from . import models
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
{
|
{
|
||||||
"name": "XML Reports",
|
"name": "XML Reports",
|
||||||
"version": "10.0.1.0.0",
|
"version": "11.0.1.0.0",
|
||||||
"category": "Reporting",
|
"category": "Reporting",
|
||||||
"website": "https://github.com/OCA/reporting-engine",
|
"website": "https://github.com/OCA/reporting-engine",
|
||||||
"author": "Grupo ESOC Ingeniería de Servicios, "
|
"author": "Grupo ESOC Ingeniería de Servicios, "
|
||||||
|
@ -14,10 +14,11 @@
|
||||||
"application": False,
|
"application": False,
|
||||||
"summary": "Allow to generate XML reports",
|
"summary": "Allow to generate XML reports",
|
||||||
"depends": [
|
"depends": [
|
||||||
"report",
|
"web",
|
||||||
],
|
],
|
||||||
"data": [
|
"data": [
|
||||||
"views/report_xml_templates.xml",
|
"views/report_xml_templates.xml",
|
||||||
|
"views/webclient_templates.xml",
|
||||||
],
|
],
|
||||||
"demo": [
|
"demo": [
|
||||||
"demo/report.xml",
|
"demo/report.xml",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
from . import main
|
from . import main
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
from odoo.addons.report.controllers import main as report
|
from odoo.addons.web.controllers import main as report
|
||||||
from odoo.http import route
|
from odoo.http import route
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,8 +19,9 @@ class ReportController(report.ReportController):
|
||||||
# XML header must be before any spaces, and it is a common error,
|
# XML header must be before any spaces, and it is a common error,
|
||||||
# so let's fix that here and make developers happier
|
# so let's fix that here and make developers happier
|
||||||
response.data = response.data.strip()
|
response.data = response.data.strip()
|
||||||
|
|
||||||
# XML files should be downloaded
|
|
||||||
response.headers.set("Content-Type", "text/xml")
|
response.headers.set("Content-Type", "text/xml")
|
||||||
|
response.headers.set('Content-length', len(response.data))
|
||||||
|
response.headers.set(
|
||||||
|
'Content-Disposition',
|
||||||
|
'attachment; filename="'+reportname+".xml")
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -11,11 +11,12 @@
|
||||||
</root>
|
</root>
|
||||||
</t>
|
</t>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<report id="demo_xml_report"
|
<report id="demo_xml_report"
|
||||||
name="report_xml.demo_report_xml_view"
|
name="report_xml.demo_report_xml_view"
|
||||||
string="Demo xml report"
|
string="Demo xml report"
|
||||||
report_type="qweb-xml"
|
report_type="qweb-xml"
|
||||||
|
print_report_name="'Demo xml report'"
|
||||||
|
file="report_xml.xml"
|
||||||
model="res.company"/>
|
model="res.company"/>
|
||||||
|
|
||||||
</odoo>
|
</odoo>
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
from . import report_action
|
from . import report_action
|
||||||
from . import report_generator
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -11,39 +11,30 @@ _logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
class ReportAction(models.Model):
|
class ReportAction(models.Model):
|
||||||
_inherit = "ir.actions.report.xml"
|
_inherit = "ir.actions.report"
|
||||||
|
|
||||||
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
|
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")])
|
||||||
|
|
||||||
def _lookup_report(self, name):
|
@api.model
|
||||||
"""Enable ``qweb-xml`` report lookup."""
|
def _get_report_from_name(self, report_name):
|
||||||
try:
|
res = super(ReportAction, self)._get_report_from_name(report_name)
|
||||||
return super(ReportAction, self)._lookup_report(name)
|
if res:
|
||||||
except Exception as ex:
|
return res
|
||||||
# Somebody thought it was a good idea to use standard exceptions
|
report_obj = self.env['ir.actions.report']
|
||||||
if "qweb-xml" not in ex.message:
|
qwebtypes = ['qweb-xml']
|
||||||
raise ex
|
conditions = [('report_type', 'in', qwebtypes),
|
||||||
else:
|
('report_name', '=', report_name)]
|
||||||
self._cr.execute(
|
context = self.env['res.users'].context_get()
|
||||||
"SELECT * FROM ir_act_report_xml WHERE report_name=%s",
|
return report_obj.with_context(context).search(conditions, limit=1)
|
||||||
(name,))
|
|
||||||
return self._cr.dictfetchone()["report_name"]
|
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def render_report(self, res_ids, name, data):
|
def render_qweb_xml(self, docids, data):
|
||||||
"""Special handling for ``qweb-xml`` reports."""
|
result = self.render_qweb_html(docids, data=data)
|
||||||
xml_report = self.search([('report_name', '=', name),
|
return etree.tostring(
|
||||||
('report_type', '=', 'qweb-xml')], limit=1)
|
etree.fromstring(
|
||||||
if xml_report:
|
str(result[0], 'UTF-8').lstrip('\n').lstrip().encode('UTF-8')
|
||||||
xml_report = xml_report.ensure_one()
|
),
|
||||||
result = self.env["report"].get_html(res_ids,
|
encoding='UTF-8',
|
||||||
xml_report.report_name,
|
xml_declaration=True,
|
||||||
data=data)
|
pretty_print=True
|
||||||
return (
|
), "xml"
|
||||||
etree.tostring(
|
|
||||||
etree.fromstring(result.strip()),
|
|
||||||
encoding='UTF-8', xml_declaration=True, pretty_print=True
|
|
||||||
), "xml")
|
|
||||||
else:
|
|
||||||
return super(ReportAction, self).render_report(
|
|
||||||
res_ids, name, data)
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
# -*- coding: utf-8 -*-
|
|
||||||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es>
|
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
||||||
|
|
||||||
import logging
|
|
||||||
|
|
||||||
from odoo import api, models
|
|
||||||
|
|
||||||
_logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class ReportGenerator(models.Model):
|
|
||||||
_inherit = "report"
|
|
||||||
|
|
||||||
@api.model
|
|
||||||
def _get_report_from_name(self, report_name):
|
|
||||||
res = super(ReportGenerator, self)._get_report_from_name(report_name)
|
|
||||||
if res:
|
|
||||||
return res
|
|
||||||
report_obj = self.env['ir.actions.report.xml']
|
|
||||||
qwebtypes = ['qweb-xml']
|
|
||||||
conditions = [('report_type', 'in', qwebtypes),
|
|
||||||
('report_name', '=', report_name)]
|
|
||||||
context = self.env['res.users'].context_get()
|
|
||||||
return report_obj.with_context(context).search(conditions, limit=1)
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
odoo.define('report_xml.report', function(require){
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var ActionManager= require('web.ActionManager');
|
||||||
|
var crash_manager = require('web.crash_manager');
|
||||||
|
var framework = require('web.framework');
|
||||||
|
|
||||||
|
ActionManager.include({
|
||||||
|
ir_actions_report: function (action, options){
|
||||||
|
var self = this;
|
||||||
|
action = _.clone(action);
|
||||||
|
if (action.report_type === 'qweb-xml') {
|
||||||
|
framework.blockUI()
|
||||||
|
var report_xml_url = 'report/xml/' + action.report_name;
|
||||||
|
if(action.context.active_ids){
|
||||||
|
report_xml_url += '/' + action.context.active_ids.join(',');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
report_xml_url += '?options=' + encodeURIComponent(JSON.stringify(action.data));
|
||||||
|
report_xml_url += '&context=' + encodeURIComponent(JSON.stringify(action.context));
|
||||||
|
}
|
||||||
|
self.getSession().get_file({
|
||||||
|
url: report_xml_url,
|
||||||
|
data: {data: JSON.stringify([
|
||||||
|
report_xml_url,
|
||||||
|
action.report_type,
|
||||||
|
])},
|
||||||
|
error: crash_manager.rpc_error.bind(crash_manager),
|
||||||
|
success: function (){
|
||||||
|
if(action && options && !action.dialog){
|
||||||
|
options.on_close();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
framework.unblockUI();
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return self._super(action, options);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -1,4 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl.html).
|
||||||
|
|
||||||
from . import test_report_xml
|
from . import test_report_xml
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# Copyright 2017 Creu Blanca
|
# Copyright 2017 Creu Blanca
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (https://www.gnuorg/licenses/agpl).
|
||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
@ -8,17 +8,12 @@ from odoo.tests import common
|
||||||
|
|
||||||
class TestXmlReport(common.TransactionCase):
|
class TestXmlReport(common.TransactionCase):
|
||||||
def test_xml(self):
|
def test_xml(self):
|
||||||
report_object = self.env['ir.actions.report.xml']
|
report_object = self.env['ir.actions.report']
|
||||||
report_name = 'report_xml.demo_report_xml_view'
|
report_name = 'report_xml.demo_report_xml_view'
|
||||||
self.assertEqual(
|
report = report_object._get_report_from_name(report_name)
|
||||||
report_name, report_object._lookup_report(report_name))
|
|
||||||
docs = self.env['res.company'].search([], limit=1)
|
docs = self.env['res.company'].search([], limit=1)
|
||||||
rep = report_object.render_report(
|
self.assertEqual(report.report_type, 'qweb-xml')
|
||||||
docs.ids, report_name, {}
|
rep = report.render(docs.ids, {})
|
||||||
)
|
|
||||||
root = etree.fromstring(rep[0])
|
root = etree.fromstring(rep[0])
|
||||||
el = root.xpath('/root/user/name')
|
el = root.xpath('/root/user/name')
|
||||||
self.assertEqual(
|
self.assertEqual(el[0].text, docs.ensure_one().name)
|
||||||
el[0].text,
|
|
||||||
docs.ensure_one().name
|
|
||||||
)
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<odoo>
|
||||||
|
<template id="report_xml.assets_backend" inherit_id="web.assets_backend">
|
||||||
|
<xpath expr="." position="inside">
|
||||||
|
<script type="text/javascript" src="/report_xml/static/src/js/report/qwebactionmanager.js"/>
|
||||||
|
</xpath>
|
||||||
|
|
||||||
|
</template>
|
||||||
|
</odoo>
|
Loading…
Reference in New Issue