From 66969f51fa579d52d1e2b9d70586852c8d3c40ea Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Wed, 5 Nov 2014 11:47:10 +0100 Subject: [PATCH] [FIX] Report: get_pdf: don't miss main elements when parsing html Main elements can have more than one class, thus can be ignored by the previous naive xpath. This patch brings a stronger xpath. --- addons/report/models/report.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/report/models/report.py b/addons/report/models/report.py index fc2bb9ba89b..55edb06fa6f 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -211,21 +211,22 @@ class Report(osv.Model): # in order to extract headers, bodies and footers. try: root = lxml.html.fromstring(html) + match_klass = "//div[contains(concat(' ', normalize-space(@class), ' '), ' {} ')]" for node in root.xpath("//html/head/style"): css += node.text - for node in root.xpath("//div[@class='header']"): + for node in root.xpath(match_klass.format('header')): body = lxml.html.tostring(node) header = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url)) headerhtml.append(header) - for node in root.xpath("//div[@class='footer']"): + for node in root.xpath(match_klass.format('footer')): body = lxml.html.tostring(node) footer = render_minimal(dict(css=css, subst=True, body=body, base_url=base_url)) footerhtml.append(footer) - for node in root.xpath("//div[@class='page']"): + for node in root.xpath(match_klass.format('page')): # Previously, we marked some reports to be saved in attachment via their ids, so we # must set a relation between report ids and report's content. We use the QWeb # branding in order to do so: searching after a node having a data-oe-model