diff --git a/addons/report/models/report.py b/addons/report/models/report.py index 21ea84ab01d..f0e2b4008ea 100644 --- a/addons/report/models/report.py +++ b/addons/report/models/report.py @@ -89,6 +89,31 @@ class Report(osv.Model): #-------------------------------------------------------------------------- # Extension of ir_ui_view.render with arguments frequently used in reports #-------------------------------------------------------------------------- + + 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. + + + + + + :param doc_id: id of the record to translate + :param model: model of the record to translate + :param lang_field': field of the record containing the lang + :param template: name of the template to translate into the lang_field + """ + ctx = context.copy() + doc = self.pool[model].browse(cr, uid, doc_id, context=ctx) + qcontext = values.copy() + # Do not force-translate if we chose to display the report in a specific lang + if ctx.get('translatable') is True: + qcontext['o'] = doc + else: + # 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 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. @@ -107,28 +132,7 @@ class Report(osv.Model): view_obj = self.pool['ir.ui.view'] def translate_doc(doc_id, model, lang_field, template): - """Helper used when a report should be translated into a specific lang. - - - - - - :param doc_id: id of the record to translate - :param model: model of the record to translate - :param lang_field': field of the record containing the lang - :param template: name of the template to translate into the lang_field - """ - ctx = context.copy() - doc = self.pool[model].browse(cr, uid, doc_id, context=ctx) - qcontext = values.copy() - # Do not force-translate if we chose to display the report in a specific lang - if ctx.get('translatable') is True: - qcontext['o'] = doc - else: - # 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.translate_doc(cr, uid, doc_id, model, lang_field, template, values, context=context) user = self.pool['res.users'].browse(cr, uid, uid) website = None diff --git a/addons/website_report/__init__.py b/addons/website_report/__init__.py index e69de29bb2d..a0526c7c636 100644 --- a/addons/website_report/__init__.py +++ b/addons/website_report/__init__.py @@ -0,0 +1,2 @@ +import controllers +import report diff --git a/addons/website_report/controllers/__init__.py b/addons/website_report/controllers/__init__.py new file mode 100644 index 00000000000..8ee9bae18d9 --- /dev/null +++ b/addons/website_report/controllers/__init__.py @@ -0,0 +1 @@ +import main diff --git a/addons/website_report/controllers/main.py b/addons/website_report/controllers/main.py new file mode 100644 index 00000000000..11b4257b6c6 --- /dev/null +++ b/addons/website_report/controllers/main.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014-Today OpenERP SA (). +# +# 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 . +# +############################################################################## + +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 diff --git a/addons/website_report/report.py b/addons/website_report/report.py new file mode 100644 index 00000000000..4da33a4d7c2 --- /dev/null +++ b/addons/website_report/report.py @@ -0,0 +1,47 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2014-Today OpenERP SA (). +# +# 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 . +# +############################################################################## + +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)