Merge pull request #814 from odoo-dev/master-report-translation-fix-sle

Master report translation fix sle
This commit is contained in:
sle-odoo 2014-06-30 18:46:13 +02:00
commit 839a70511c
10 changed files with 117 additions and 174 deletions

View File

@ -10,22 +10,22 @@
<div class="row mt32 mb32">
<div class="col-xs-3">
<strong>Chart of Tax:</strong>
<p t-esc="account"/>
<p t-esc="get_account(data)"/>
</div>
<div class="col-xs-3" t-if="fiscalyear">
<div class="col-xs-3">
<strong>Fiscal Year:</strong>
<p t-esc="fiscalyear"/>
<p t-esc="get_fiscalyear(data)"/>
</div>
<div class="col-xs-3" t-if="period_from and period_to">
<div class="col-xs-3">
<strong>Periods:</strong>
<p>
Start Period: <span t-esc="period_from"/><br/>
End Period: <span t-esc="period_to"/>
Start Period: <span t-esc="get_start_period(data)"/><br/>
End Period: <span t-esc="get_end_period(data)"/>
</p>
</div>
<div class="col-xs-3">
<strong>Based On:</strong>
<p t-esc="based_on"/>
<p t-esc="get_basedon(data)"/>
</div>
</div>

View File

@ -50,7 +50,12 @@ class ReportController(Controller):
if data.get('options'):
options_data = simplejson.loads(data['options'])
if data.get('context'):
context.update(simplejson.loads(data['context']))
# Ignore 'lang' here, because the context in data is the one from the webclient *but* if
# the user explicitely wants to change the lang, this mechanism overwrites it.
data_context = simplejson.loads(data['context'])
if data_context.get('lang'):
del data_context['lang']
context.update(data_context)
if converter == 'html':
html = report_obj.get_html(cr, uid, docids, reportname, data=options_data, context=context)

View File

@ -34,10 +34,8 @@ import lxml.html
import cStringIO
import subprocess
from distutils.version import LooseVersion
try:
from pyPdf import PdfFileWriter, PdfFileReader
except ImportError:
PdfFileWriter = PdfFileReader = None
from functools import partial
from pyPdf import PdfFileWriter, PdfFileReader
_logger = logging.getLogger(__name__)
@ -71,23 +69,6 @@ class Report(osv.Model):
public_user = None
MINIMAL_HTML_PAGE = """
<base href="{base_url}">
<!DOCTYPE html>
<html style="height: 0;">
<head>
<link href="/report/static/src/css/reset.min.css" rel="stylesheet"/>
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<style type='text/css'>{css}</style>
{subst}
</head>
<body class="container" onload="subst()">
{body}
</body>
</html>"""
#--------------------------------------------------------------------------
# Extension of ir_ui_view.render with arguments frequently used in reports
#--------------------------------------------------------------------------
@ -133,7 +114,9 @@ class Report(osv.Model):
user = self.pool['res.users'].browse(cr, uid, uid)
website = None
if request and hasattr(request, 'website'):
website = request.website
if request.website is not None:
website = request.website
context.update(translatable=context.get('lang') != request.website.default_lang_code)
values.update(
time=time,
translate_doc=translate_doc,
@ -141,7 +124,7 @@ class Report(osv.Model):
user=user,
res_company=user.company_id,
website=website,
editable_no_editor=True,
editable_no_editor=_("The preferred way to edit a report is to use the HTML Editor"),
)
return view_obj.render(cr, uid, template, values, context=context)
@ -191,13 +174,16 @@ class Report(osv.Model):
paperformat = report.paperformat_id
# Preparing the minimal html pages
subst = "<script src='/report/static/src/js/subst.js'></script> "
css = '' # Will contain local css
headerhtml = []
contenthtml = []
footerhtml = []
base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url')
# Minimal page renderer
view_obj = self.pool['ir.ui.view']
render_minimal = partial(view_obj.render, cr, uid, 'report.minimal_layout', context=context)
# The received html report must be simplified. We convert it in a xml tree
# in order to extract headers, bodies and footers.
try:
@ -208,12 +194,12 @@ class Report(osv.Model):
for node in root.xpath("//div[@class='header']"):
body = lxml.html.tostring(node)
header = self.MINIMAL_HTML_PAGE.format(css=css, subst=subst, body=body, base_url=base_url)
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']"):
body = lxml.html.tostring(node)
footer = self.MINIMAL_HTML_PAGE.format(css=css, subst=subst, body=body, base_url=base_url)
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']"):
@ -230,7 +216,7 @@ class Report(osv.Model):
reportid = False
body = lxml.html.tostring(node)
reportcontent = self.MINIMAL_HTML_PAGE.format(css=css, subst='', body=body, base_url=base_url)
reportcontent = render_minimal(dict(css=css, subst=False, body=body, base_url=base_url))
# FIXME: imo the best way to extract record id from html reports is by using the
# qweb branding. As website editor is not yet splitted in a module independant from
@ -254,11 +240,10 @@ class Report(osv.Model):
specific_paperformat_args[attribute[0]] = attribute[1]
# Run wkhtmltopdf process
pdf = self._generate_wkhtml_pdf(
return self._run_wkhtmltopdf(
cr, uid, headerhtml, footerhtml, contenthtml, context.get('landscape'),
paperformat, specific_paperformat_args, save_in_attachment
)
return pdf
def get_action(self, cr, uid, ids, report_name, data=None, context=None):
"""Return an action of type ir.actions.report.xml.
@ -329,7 +314,7 @@ class Report(osv.Model):
def _check_wkhtmltopdf(self):
return wkhtmltopdf_state
def _generate_wkhtml_pdf(self, cr, uid, headers, footers, bodies, landscape, paperformat, spec_paperformat_args=None, save_in_attachment=None):
def _run_wkhtmltopdf(self, cr, uid, headers, footers, bodies, landscape, paperformat, spec_paperformat_args=None, save_in_attachment=None):
"""Execute wkhtmltopdf as a subprocess in order to convert html given in input into a pdf
document.

View File

@ -1,55 +1,31 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="layout" inherit_id="web.layout" primary="True">
<!-- Add report attributes -->
<xpath expr="//html" position="attributes">
<attribute name="t-att-data-report-margin-top">data_report_margin_top if data_report_margin_top else None</attribute>
<attribute name="t-att-data-report-header-spacing">data_report_header_spacing if data_report_header_spacing else None</attribute>
<attribute name="t-att-data-report-dpi">data_report_dpi if data_report_dpi else None</attribute>
</xpath>
<!-- Add report style -->
<xpath expr="//head" position="inside">
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<style type="text/css">
<t t-call="report.style"/>
</style>
</xpath>
<!-- Remove conflicting style -->
<xpath expr="//head/link[@href='/web/static/src/css/full.css']" position="replace"></xpath>
</template>
<template id="html_container">
&lt;!DOCTYPE html&gt;
<html t-att-lang="lang and lang.replace('_', '-')"
t-att-data-editable="'1' if editable else None"
t-att-data-view-xmlid="xmlid if editable else None"
t-att-data-main-object="repr(main_object) if editable else None"
t-att-data-report-margin-top="data_report_margin_top if data_report_margin_top else None"
t-att-data-report-header-spacing="data_report_header_spacing if data_report_header_spacing else None"
t-att-data-report-dpi="data_report_dpi if data_report_dpi else None"
t-att-data-oe-company-name="res_company.name">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<t t-if="main_object and 'website_meta_title' in main_object">
<t t-set="title" t-value="main_object.website_meta_title"/>
</t>
<t t-if="not title and main_object and 'name' in main_object">
<t t-set="additional_title" t-value="main_object.name"/>
</t>
<meta name="description" t-att-value="main_object and 'website_meta_description' in main_object
and main_object.website_meta_description or website_meta_description"/>
<meta name="keywords" t-att-value="main_object and 'website_meta_keywords' in main_object
and main_object.website_meta_keywords or website_meta_keywords"/>
<link id="bootstrap_css" rel='stylesheet' href='/web/static/lib/bootstrap/css/bootstrap.css' t-ignore="true"/>
<link rel="stylesheet" type="text/css" href='/website/static/src/css/website.css'/>
<style type="text/css">
<t t-call="report.style"/>
</style>
<link rel='stylesheet' href='/web/static/lib/fontawesome/css/font-awesome.css'/>
<script type="text/javascript" src="/web/static/lib/es5-shim/es5-shim.min.js"></script>
<script type="text/javascript" src="/web/static/lib/underscore/underscore.js"></script>
<script type="text/javascript" src="/web/static/lib/underscore.string/lib/underscore.string.js"></script>
<script type="text/javascript" src="/web/static/lib/jquery/jquery.js"></script>
<script type="text/javascript" src="/web/static/lib/bootstrap/js/bootstrap.js"></script>
<script type="text/javascript" src="/web/static/lib/qweb/qweb2.js"></script>
<script type="text/javascript" src="/web/static/src/js/openerpframework.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.js"></script>
<script t-if="not translatable" type="text/javascript" src="/website/static/src/js/website.snippets.animation.js"></script>
<t t-raw="head or ''" name='layout_head'/>
</head>
<body class="container">
<div id="wrapwrap">
<t t-raw="0"/>
</div>
</body>
</html>
<t t-set="body_classname" t-value="'container'"/>
<t t-call="report.layout">
<t t-raw="0"/>
</t>
</template>
<template id="style">
@ -164,5 +140,25 @@
<t t-raw="0" />
</template>
<template id="minimal_layout">
<t t-raw="'&lt;base href=%s&gt;' % base_url"/>
&lt;!DOCTYPE html&gt;
<html style="height: 0;">
<head>
<link href="/report/static/src/css/reset.min.css" rel="stylesheet"/>
<link href="/web/static/lib/bootstrap/css/bootstrap.css" rel="stylesheet"/>
<link href="/website/static/src/css/website.css" rel="stylesheet"/>
<link href="/web/static/lib/fontawesome/css/font-awesome.css" rel="stylesheet"/>
<style type='text/css'><t t-raw="css"/></style>
<t t-if="subst is True">
<script src='/report/static/src/js/subst.js'></script>
</t>
</head>
<body class="container" onload="subst()">
<t t-raw="body"/>
</body>
</html>
</template>
</data>
</openerp>

View File

@ -65,7 +65,7 @@
<tbody class="sale_tbody">
<tr t-foreach="o.order_line" t-as="l">
<td>
<span t-field="l.name"/>
<span t-field="l.name"/>
</td>
<td>
<span t-esc="', '.join(map(lambda x: x.name, l.tax_id))"/>

View File

@ -244,7 +244,7 @@ class website(osv.osv):
return is_website_publisher
def is_user(self, cr, uid, ids, context=None):
return self.pool['res.users'].has_group(cr, request.uid, 'base.group_user')
return self.pool['res.users'].has_group(cr, uid, 'base.group_user')
def get_template(self, cr, uid, ids, template, context=None):
if isinstance(template, (int, long)):

View File

@ -4,6 +4,7 @@
<!-- Front-end/Back-end integration -->
<template id="user_navbar" inherit_id="website.layout" groups="base.group_user">
<xpath expr="//body/div['id=wrawrap']" position="before">
<t t-if="website and menu_data">
<nav id="oe_main_menu_navbar" class="navbar navbar-inverse" role="navigation">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#oe_applications">
@ -79,6 +80,7 @@
</li>
</ul>
</nav>
</t>
</xpath>
</template>
</data>

View File

@ -57,7 +57,7 @@
<template id="layout" name="Main layout">&lt;!DOCTYPE html&gt;
<html t-att-lang="lang and lang.replace('_', '-')"
t-att-data-website-id="website.id if editable else None"
t-att-data-website-id="website.id if editable and website else None"
t-att-data-editable="'1' if editable else None"
t-att-data-editable-no-editor="editable_no_editor or None"
t-att-data-translatable="'1' if translatable else None"
@ -82,10 +82,10 @@
and main_object.website_meta_keywords or website_meta_keywords"/>
<title><t t-esc="title"/></title>
<t t-set="languages" t-value="website.get_languages()"/>
<t t-if="request.website_multilang">
<t t-set="languages" t-value="website.get_languages() if website else None"/>
<t t-if="request and request.website_multilang">
<t t-foreach="languages" t-as="lg">
<t t-set="force_lang" t-value="lg[0] if lg[0] != website.default_lang_code else None"/>
<t t-set="force_lang" t-value="lg[0] if website and lg[0] != website.default_lang_code else None"/>
<link rel="alternate" t-att-href="url_for(request.httprequest.path + '?' + keep_query(), lang=force_lang)" t-att-hreflang="lg[0].replace('_', '-').lower()" />
</t>
</t>
@ -150,7 +150,7 @@
</div>
</footer>
</div>
<t t-if="website.google_analytics_key">
<t t-if="website and website.google_analytics_key">
<script>
(function(b,o,i,l,e,r){b.GoogleAnalyticsObject=l;b[l]||(b[l]=
function(){(b[l].q=b[l].q||[]).push(arguments)});b[l].l=+new Date;

View File

@ -4,7 +4,7 @@
<template id="header" inherit_id="website.layout" name="LiveChat Import (internal) Scripts">
<xpath expr="//head" position="inside">
<t t-if="website.channel_id">
<t t-if="website and website.channel_id">
<t t-raw="website.channel_id.script_internal"/>
</t>
</xpath>

View File

@ -1,92 +1,47 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<template id="editor_head" inherit_id="report.html_container" name="Editor" groups="base.group_website_publisher">
<template id="layout" inherit_id="website.layout" primary="True">
<!-- Add report attributes -->
<xpath expr="//html" position="attributes">
<attribute name="t-att-data-website-id">website.id if editable and website else None</attribute>
<attribute name="t-att-data-translatable">'1' if translatable else None</attribute>
<attribute name="t-att-data-report-margin-top">data_report_margin_top if data_report_margin_top else None</attribute>
<attribute name="t-att-data-report-header-spacing">data_report_header_spacing if data_report_header_spacing else None</attribute>
<attribute name="t-att-data-report-dpi">data_report_dpi if data_report_dpi else None</attribute>
</xpath>
<!-- Add report style -->
<xpath expr="//head" position="inside">
<style type="text/css">
<t t-call="report.style"/>
</style>
</xpath>
<xpath expr="//body" position="attributes">
<attribute name="style">padding-top: 51px;</attribute>
<attribute name="class">container</attribute>
</xpath>
<xpath expr="//body" position="inside">
<div id="website-top-navbar-placeholder" class="navbar navbar-inverse navbar-fixed-top hidden-xs">
<div class="navbar-header">
<form class="navbar-form navbar-left">
<button type="button" class="btn btn-primary">Edit</button>
</form>
</div>
<div class="collapse navbar-collapse navbar-edit-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="#" onclick="return false;"><i class="fa fa-mobile" title="Mobile preview"/></a></li>
<li class="divider-vertical"/>
<li><a href="#" onclick="return false;"><span title="Promote page on the web">Promote</span></a></li>
<li class="dropdown">
<a href="#" onclick="return false;">Content <span class="caret"/></a>
</li>
<li class="dropdown">
<a href="#" onclick="return false;">Customize <span class="caret"/></a>
</li>
<li class="dropdown">
<a href="#" onclick="return false;">Help <span class="caret"/></a>
</li>
</ul>
</div>
</div>
<xpath expr="//header" position="replace"/>
<xpath expr="//footer" position="replace">
<ul class="list-inline js_language_selector mt16" t-if="(request and request.website_multilang and len(languages) &gt; 1) or (website and editable)">
<li t-foreach="languages" t-as="lg">
<a t-att-href="url_for(request.httprequest.path + '?' + keep_query(), lang=lg[0])"
t-att-data-default-lang="editable and 'true' if website and lg[0] == website.default_lang_code else None">
<t t-esc="lg[1].split('/').pop()"/>
</a>
</li>
<li groups="base.group_website_publisher">
<t t-set="url_return" t-value="url_for('', '[lang]') + '?' + keep_query()"/>
<a t-attf-href="/web#action=base.action_view_base_language_install&amp;website_id=#{website.id if website else ''}&amp;url_return=#{url_return}">
<i class="fa fa-plus-circle"/>
Add a language...
</a>
</li>
</ul>
</xpath>
<xpath expr='//t[@name="layout_head"]' position="before">
<link rel='stylesheet' href='/website/static/src/css/snippets.css'/>
<link rel='stylesheet' href='/website/static/src/css/editor.css'/>
</template>
<link rel="stylesheet" href="/web/static/lib/select2/select2.css"/>
<link rel="stylesheet" href="/website/static/lib/select2-bootstrap-css/select2-bootstrap.css"/>
<link rel='stylesheet' href="/web/static/lib/jquery.ui/css/smoothness/jquery-ui-1.9.1.custom.css"/>
<script type="text/javascript" src="/web/static/lib/select2/select2.js"></script>
<script type="text/javascript" src="/web/static/lib/ckeditor/ckeditor.js"></script>
<script type="text/javascript" src="/website/static/lib/ace/ace.js"></script>
<script type="text/javascript" src="/website/static/lib/vkbeautify/vkbeautify.0.99.00.beta.js"></script>
<script type="text/javascript" src="/web/static/lib/jquery.ui/js/jquery-ui-1.9.1.custom.js"></script>
<!-- mutation observers shim backed by mutation events (8 < IE < 11, Safari < 6, FF < 14, Chrome < 17) -->
<script type="text/javascript" src="/website/static/lib//jquery.mjs.nestedSortable/jquery.mjs.nestedSortable.js"></script>
<script type="text/javascript" src="/website/static/lib/MutationObservers/test/sidetable.js"></script>
<script type="text/javascript" src='/website/static/lib/nearest/jquery.nearest.js'></script>
<script type="text/javascript" src="/website/static/lib/MutationObservers/MutationObserver.js"></script>
<script type="text/javascript" src="/website/static/lib/jquery.placeholder/jquery.placeholder.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.editor.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.menu.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.editor.newpage.js"></script> <!-- groups="base.group_website_designer" -->
<script type="text/javascript" src="/website/static/src/js/website.contentMenu.js"></script> <!-- groups="base.group_website_designer" -->
<script type="text/javascript" src="/website/static/src/js/website.mobile.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.seo.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.snippets.editor.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.ace.js"></script>
<script type="text/javascript" src="/website/static/src/js/website.translator.js"></script>
<script type="text/javascript" src="/website/static/src/js/jQuery.transfo.js"></script>
</xpath>
<xpath expr='//body[@class="container"]/div[@id="wrapwrap"]' position="before">
<t t-set="languages" t-value="website.get_languages() if website else None"/>
<t t-if="languages">
<ul class="list-inline js_language_selector mt16" t-if="(len(languages) &gt; 1 or editable)">
<li t-foreach="languages" t-as="lg">
<a t-att-href="url_for('', lang=lg[0]) + '?' + keep_query()"
t-att-data-default-lang="editable and 'true' if lg[0] == website.default_lang_code else None">
<t t-esc="lg[1].split('/').pop()"/>
</a>
</li>
<li groups="base.group_website_publisher">
<t t-set="url_return" t-value="url_for('', '[lang]') + '?' + keep_query()"/>
<a t-attf-href="/web#action=base.action_view_base_language_install&amp;website_id=#{website.id}&amp;url_return=#{url_return}">
<i class="fa fa-plus-circle"/>
Add a language...
</a>
</li>
</ul>
<template id="website_html_container" inherit_id="report.html_container">
<xpath expr="//t[@t-call='report.layout']" position="replace">
<t t-call="website_report.layout">
<t t-raw="0"/>
</t>
</xpath>
</template>