[FIX] report : translation of report using website editor
In the website editor, the translations are loaded using the route 'get_view_translations', which returns the translations of the templates loaded by the website (t-call calls) The thing is, report templates use the 'translate_doc' method to actually load the report, translated in the partner language, and the templates loaded by this method are not seen by the website, therefore, when calling 'get_view_translations', those report templates were just ignored, thus their translations are not loaded. This rev. injects the templates loaded with translate_doc when rendering the report into the method 'customize_template_get' (which is used by 'get_view_translations' to retrieve the loaded templates). The translations of the reports are therefore now loaded corretly when hitting the "translate" button in the website editor for reports. Besides, this rev. has as (good) side-effect to add the template, in the template selection input when editing using the HTML editor. opw-620713
This commit is contained in:
parent
184ed718a3
commit
0167acbb52
|
@ -89,24 +89,8 @@ class Report(osv.Model):
|
|||
#--------------------------------------------------------------------------
|
||||
# Extension of ir_ui_view.render with arguments frequently used in reports
|
||||
#--------------------------------------------------------------------------
|
||||
def render(self, cr, uid, ids, template, values=None, context=None):
|
||||
"""Allow to render a QWeb template python-side. This function returns the 'ir.ui.view'
|
||||
render but embellish it with some variables/methods used in reports.
|
||||
|
||||
:param values: additionnal methods/variables used in the rendering
|
||||
:returns: html representation of the template
|
||||
"""
|
||||
if values is None:
|
||||
values = {}
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
context = dict(context, inherit_branding=True) # Tell QWeb to brand the generated html
|
||||
|
||||
view_obj = self.pool['ir.ui.view']
|
||||
|
||||
def translate_doc(doc_id, model, lang_field, template):
|
||||
def translate_doc(self, cr, uid, doc_id, model, lang_field, template, values, context=None):
|
||||
"""Helper used when a report should be translated into a specific lang.
|
||||
|
||||
<t t-foreach="doc_ids" t-as="doc_id">
|
||||
|
@ -128,7 +112,27 @@ class Report(osv.Model):
|
|||
# Reach the lang we want to translate the doc into
|
||||
ctx['lang'] = eval('doc.%s' % lang_field, {'doc': doc})
|
||||
qcontext['o'] = self.pool[model].browse(cr, uid, doc_id, context=ctx)
|
||||
return view_obj.render(cr, uid, template, qcontext, context=ctx)
|
||||
return self.pool['ir.ui.view'].render(cr, uid, template, qcontext, context=ctx)
|
||||
|
||||
def render(self, cr, uid, ids, template, values=None, context=None):
|
||||
"""Allow to render a QWeb template python-side. This function returns the 'ir.ui.view'
|
||||
render but embellish it with some variables/methods used in reports.
|
||||
|
||||
:param values: additionnal methods/variables used in the rendering
|
||||
:returns: html representation of the template
|
||||
"""
|
||||
if values is None:
|
||||
values = {}
|
||||
|
||||
if context is None:
|
||||
context = {}
|
||||
|
||||
context = dict(context, inherit_branding=True) # Tell QWeb to brand the generated html
|
||||
|
||||
view_obj = self.pool['ir.ui.view']
|
||||
|
||||
def translate_doc(doc_id, model, lang_field, template):
|
||||
return self.translate_doc(cr, uid, doc_id, model, lang_field, template, values, context=context)
|
||||
|
||||
user = self.pool['res.users'].browse(cr, uid, uid)
|
||||
website = None
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
import controllers
|
||||
import report
|
|
@ -0,0 +1 @@
|
|||
import main
|
|
@ -0,0 +1,33 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>).
|
||||
#
|
||||
# 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.addons.website.controllers.main import Website
|
||||
from openerp.http import request, route
|
||||
|
||||
|
||||
class Website(Website):
|
||||
|
||||
@route()
|
||||
def customize_template_get(self, xml_id, full=False):
|
||||
res = super(Website, self).customize_template_get(xml_id, full=full)
|
||||
if full and request.session.get('report_view_ids'):
|
||||
res += request.session['report_view_ids']
|
||||
return res
|
|
@ -0,0 +1,47 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>).
|
||||
#
|
||||
# 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.addons.web.http import request
|
||||
from openerp.osv import osv
|
||||
|
||||
|
||||
class Report(osv.Model):
|
||||
_inherit = 'report'
|
||||
|
||||
def translate_doc(self, cr, uid, doc_id, model, lang_field, template, values, context=None):
|
||||
if request and hasattr(request, 'website'):
|
||||
if request.website is not None:
|
||||
v = request.website.get_template(template)
|
||||
request.session['report_view_ids'].append({
|
||||
'name': v.name,
|
||||
'id': v.id,
|
||||
'xml_id': v.xml_id,
|
||||
'inherit_id': v.inherit_id.id,
|
||||
'header': False,
|
||||
'active': v.active,
|
||||
})
|
||||
return super(Report, self).translate_doc(cr, uid, doc_id, model, lang_field, template, values, context=context)
|
||||
|
||||
def render(self, cr, uid, ids, template, values=None, context=None):
|
||||
if request and hasattr(request, 'website'):
|
||||
if request.website is not None:
|
||||
request.session['report_view_ids'] = []
|
||||
return super(Report, self).render(cr, uid, ids, template, values=values, context=context)
|
Loading…
Reference in New Issue