Jairo Llopis
10 years ago
7 changed files with 3364 additions and 0 deletions
-
82report_xml/README.rst
-
19report_xml/__init__.py
-
32report_xml/__openerp__.py
-
40report_xml/controllers.py
-
70report_xml/models.py
-
BINreport_xml/static/description/icon.png
-
3121report_xml/static/description/icon.svg
@ -0,0 +1,82 @@ |
|||||
|
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg |
||||
|
:alt: License: AGPL-3 |
||||
|
|
||||
|
Qweb XML Reports |
||||
|
================ |
||||
|
|
||||
|
This module was written to extend the functionality of the reporting engine to |
||||
|
support XML reports and allow modules to generate them by code or by QWeb |
||||
|
templates. |
||||
|
|
||||
|
Installation |
||||
|
============ |
||||
|
|
||||
|
To install this module, you need to: |
||||
|
|
||||
|
* Install the repository `reporting-engine`_. |
||||
|
|
||||
|
Configuration |
||||
|
============= |
||||
|
|
||||
|
No manual configuration is needed. |
||||
|
|
||||
|
Usage |
||||
|
===== |
||||
|
|
||||
|
This module is technical, so its usage instructions are intended for module |
||||
|
developers. |
||||
|
|
||||
|
To use this module, you need to: |
||||
|
|
||||
|
* Create a module. |
||||
|
* Make it depend on this one. |
||||
|
* Follow `instructions to create reports`_ having in mind that the |
||||
|
``report_type`` field in your ``ir.actions.report.xml`` record must be |
||||
|
``qweb-xml``. |
||||
|
|
||||
|
In case you want to create a `custom report`_, the instructions remain the same |
||||
|
as for HTML reports, and the method that you must override is also called |
||||
|
``render_html``, even when this time you are creating a XML report. |
||||
|
|
||||
|
You can visit http://<server-address>/report/xml/<module.report_name>/<ids> |
||||
|
to see your XML report online as a web page. |
||||
|
|
||||
|
For further information, please visit: |
||||
|
|
||||
|
* https://www.odoo.com/forum/help-1 |
||||
|
* https://github.com/OCA/reporting-engine |
||||
|
|
||||
|
Known issues / Roadmap |
||||
|
====================== |
||||
|
|
||||
|
None |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
* Icon taken from http://commons.wikimedia.org/wiki/File:Text-xml.svg. |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Jairo Llopis <j.llopis@grupoesoc.es> |
||||
|
|
||||
|
Maintainer |
||||
|
---------- |
||||
|
|
||||
|
.. image:: https://odoo-community.org/logo.png |
||||
|
:alt: Odoo Community Association |
||||
|
:target: https://odoo-community.org |
||||
|
|
||||
|
This module is maintained by the OCA. |
||||
|
|
||||
|
OCA, or the Odoo Community Association, is a nonprofit organization whose |
||||
|
mission is to support the collaborative development of Odoo features and |
||||
|
promote its widespread use. |
||||
|
|
||||
|
To contribute to this module, please visit http://odoo-community.org. |
||||
|
|
||||
|
|
||||
|
.. _reporting-engine: https://github.com/OCA/reporting-engine |
||||
|
.. _instructions to create reports: https://www.odoo.com/documentation/8.0/reference/reports.html |
||||
|
.. _custom report: https://www.odoo.com/documentation/8.0/reference/reports.html#custom-reports |
@ -0,0 +1,19 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
|
||||
|
# Odoo, Open Source Management Solution |
||||
|
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
from . import controllers, models |
@ -0,0 +1,32 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
|
||||
|
# Odoo, Open Source Management Solution |
||||
|
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
{ |
||||
|
"name": "Qweb XML Reports", |
||||
|
"version": "1.0", |
||||
|
"category": "Reporting", |
||||
|
"author": "Odoo Community Association (OCA), Grupo ESOC", |
||||
|
"license": "AGPL-3", |
||||
|
"website": "https://odoo-community.org/", |
||||
|
"installable": True, |
||||
|
"application": False, |
||||
|
"summary": "Allow to generate XML reports", |
||||
|
"depends": [ |
||||
|
"report", |
||||
|
], |
||||
|
} |
@ -0,0 +1,40 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
|
||||
|
# Odoo, Open Source Management Solution |
||||
|
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
from openerp.http import route |
||||
|
from openerp.addons.report.controllers import main as report |
||||
|
|
||||
|
|
||||
|
class ReportController(report.ReportController): |
||||
|
@route() |
||||
|
def report_routes(self, reportname, docids=None, converter=None, **data): |
||||
|
# Trick the main reporter to think we want an HTML report |
||||
|
new_converter = converter if converter != "xml" else "html" |
||||
|
response = super(ReportController, self).report_routes( |
||||
|
reportname, docids, new_converter, **data) |
||||
|
|
||||
|
# If it was an XML report, just download the generated response |
||||
|
if converter == "xml": |
||||
|
# XML header must be before any spaces, and it is a common error, |
||||
|
# so let's fix that here and make developers happier |
||||
|
response.data = response.data.strip() |
||||
|
|
||||
|
# XML files should be downloaded |
||||
|
response.headers.set("Content-Type", "text/xml") |
||||
|
|
||||
|
return response |
@ -0,0 +1,70 @@ |
|||||
|
# -*- encoding: utf-8 -*- |
||||
|
|
||||
|
# Odoo, Open Source Management Solution |
||||
|
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es> |
||||
|
# |
||||
|
# This program is free software: you can redistribute it and/or modify |
||||
|
# it under the terms of the GNU Affero General Public License as published by |
||||
|
# the Free Software Foundation, either version 3 of the License, or |
||||
|
# (at your option) any later version. |
||||
|
# |
||||
|
# This program is distributed in the hope that it will be useful, |
||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
|
# GNU Affero General Public License for more details. |
||||
|
# |
||||
|
# You should have received a copy of the GNU Affero General Public License |
||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
||||
|
|
||||
|
from openerp import api, fields, models |
||||
|
|
||||
|
|
||||
|
class ReportAction(models.Model): |
||||
|
_inherit = "ir.actions.report.xml" |
||||
|
|
||||
|
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")]) |
||||
|
|
||||
|
def _lookup_report(self, cr, name): |
||||
|
"""Enable ``qweb-xml`` report lookup.""" |
||||
|
try: |
||||
|
super(ReportAction, self)._lookup_report(cr, name) |
||||
|
except Exception as ex: |
||||
|
# Somebody thought it was a good idea to use standard exceptions |
||||
|
if "qweb-xml" not in ex.message: |
||||
|
raise ex |
||||
|
else: |
||||
|
cr.execute( |
||||
|
"SELECT * FROM ir_act_report_xml WHERE report_name=%s", |
||||
|
(name,)) |
||||
|
return cr.dictfetchone()["report_name"] |
||||
|
|
||||
|
@api.model |
||||
|
def render_report(self, res_ids, name, data): |
||||
|
"""Special handling for ``qweb-xml`` reports.""" |
||||
|
if data.get("report_type") == u"qweb-xml": |
||||
|
new_report = self._lookup_report(name) |
||||
|
recs = self.env[self.env.context["active_model"]].browse(res_ids) |
||||
|
result = self.env["report"].get_html(recs, new_report, data=data) |
||||
|
|
||||
|
# XML with spaces before the <?xml tag will fail, and trailing ones |
||||
|
# do nothing, so let's strip them and make everyone happier |
||||
|
result = (result.strip(), "xml") |
||||
|
else: |
||||
|
result = super(ReportAction, self).render_report( |
||||
|
res_ids, name, data) |
||||
|
|
||||
|
return result |
||||
|
|
||||
|
|
||||
|
class ReportGenerator(models.Model): |
||||
|
_inherit = "report" |
||||
|
|
||||
|
@api.model |
||||
|
def _get_report_from_name(self, report_name): |
||||
|
"""Allow to view ``qweb-xml`` reports as web pages.""" |
||||
|
try: |
||||
|
super(ReportGenerator, self)._get_report_from_name(report_name) |
||||
|
except IndexError: |
||||
|
return self.env["ir.actions.report.xml"].search( |
||||
|
[("report_type", "=", "qweb-xml"), |
||||
|
("report_name", "=", report_name)])[0] |
After Width: 100 | Height: 100 | Size: 4.2 KiB |
3121
report_xml/static/description/icon.svg
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
Write
Preview
Loading…
Cancel
Save
Reference in new issue