From 8b8fa39bfc92dc4edcfeb00a68ccdff637d93d56 Mon Sep 17 00:00:00 2001 From: Jairo Llopis Date: Mon, 15 Jun 2015 12:36:01 +0200 Subject: [PATCH] Clearer code comments, add logging. --- report_xml/models.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/report_xml/models.py b/report_xml/models.py index c8234238..c83017a7 100644 --- a/report_xml/models.py +++ b/report_xml/models.py @@ -16,10 +16,14 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . +import logging from lxml import etree from openerp import api, fields, models +_logger = logging.getLogger(__name__) + + class ReportAction(models.Model): _inherit = "ir.actions.report.xml" @@ -93,15 +97,29 @@ class XSDCheckedReport(models.AbstractModel): If ``context`` contains a dict called ``docargs``, it will be used as the Qweb context. The special key ``docs`` will be added to ``docargs`` automatically if missing. + """ + # Qweb context docargs = self.env.context.get("docargs", dict()) - xsd = etree.XMLSchema(etree.XML(self.xsd())) if "docs" not in docargs: docargs["docs"] = (self.env[self.env.context["active_model"]] .browse(self.env.context["active_ids"])) + + # Load XSD + xsd = etree.XML(self.xsd()) + _logger.debug("XSD schema contents: %s", etree.tostring(xsd)) + xsd = etree.XMLSchema(xsd) parser = etree.XMLParser(schema=xsd) + + # Generate XML report result = (self.env["report"] .render(self._name[len("report."):], docargs) .strip()) - etree.fromstring(result, parser) + + # Validate XML with XSD + try: + etree.fromstring(result, parser) + except Exception as error: + _logger.error(result) + raise error return result