forked from OCA/reporting-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
157 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
# -*- encoding: utf-8 -*- | ||
# Copyright (C) 2014-2015 Grupo ESOC <www.grupoesoc.es> | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import controllers, models | ||
from . import controllers | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<odoo> | ||
|
||
<template id="demo_report_xml_view"> | ||
<t t-call="report_xml.utf8_header"> | ||
<root> | ||
<user t-foreach="docs" t-as="doc"> | ||
<name t-esc="doc.name"/> | ||
<vat t-esc="doc.vat"/> | ||
</user> | ||
</root> | ||
</t> | ||
</template> | ||
|
||
<report id="demo_xml_report" | ||
name="report_xml.demo_report_xml_view" | ||
string="Demo xml report" | ||
report_type="qweb-xml" | ||
model="res.company"/> | ||
|
||
</odoo> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import report_action | ||
from . import report_generator |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# -*- 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, fields, models | ||
from lxml import etree | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
class ReportAction(models.Model): | ||
_inherit = "ir.actions.report.xml" | ||
|
||
report_type = fields.Selection(selection_add=[("qweb-xml", "XML")]) | ||
|
||
def _lookup_report(self, name): | ||
"""Enable ``qweb-xml`` report lookup.""" | ||
try: | ||
return super(ReportAction, self)._lookup_report(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: | ||
self._cr.execute( | ||
"SELECT * FROM ir_act_report_xml WHERE report_name=%s", | ||
(name,)) | ||
return self._cr.dictfetchone()["report_name"] | ||
|
||
@api.model | ||
def render_report(self, res_ids, name, data): | ||
"""Special handling for ``qweb-xml`` reports.""" | ||
xml_report = self.search([('report_name', '=', name), | ||
('report_type', '=', 'qweb-xml')], limit=1) | ||
if xml_report: | ||
xml_report = xml_report.ensure_one() | ||
result = self.env["report"].get_html(res_ids, | ||
xml_report.report_name, | ||
data=data) | ||
return ( | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# -*- coding: utf-8 -*- | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import test_report_xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2017 Creu Blanca | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from lxml import etree | ||
from odoo.tests import common | ||
|
||
|
||
class TestXmlReport(common.TransactionCase): | ||
def test_xml(self): | ||
report_object = self.env['ir.actions.report.xml'] | ||
report_name = 'report_xml.demo_report_xml_view' | ||
self.assertEqual( | ||
report_name, report_object._lookup_report(report_name)) | ||
docs = self.env['res.company'].search([], limit=1) | ||
rep = report_object.render_report( | ||
docs.ids, report_name, {} | ||
) | ||
root = etree.fromstring(rep[0]) | ||
el = root.xpath('/root/user/name') | ||
self.assertEqual( | ||
el[0].text, | ||
docs.ensure_one().name | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<openerp> | ||
<data> | ||
<odoo> | ||
|
||
<template id="utf8_header"> | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<t t-raw="0"/> | ||
</template> | ||
|
||
</data> | ||
</openerp> | ||
</odoo> |