2014-04-02 16:23:44 +00:00
|
|
|
# -*- 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.osv import osv
|
|
|
|
|
|
|
|
|
|
|
|
class AbstractReport(osv.AbstractModel):
|
|
|
|
"""Model used to embed old style reports"""
|
|
|
|
_name = 'report.abstract_report'
|
|
|
|
_template = None
|
|
|
|
_wrapped_report_class = None
|
|
|
|
|
|
|
|
def render_html(self, cr, uid, ids, data=None, context=None):
|
2014-07-06 14:44:26 +00:00
|
|
|
context = dict(context or {})
|
2014-04-02 16:23:44 +00:00
|
|
|
|
|
|
|
# If the key 'landscape' is present in data['form'], passing it into the context
|
|
|
|
if data and data.get('form', {}).get('landscape'):
|
|
|
|
context['landscape'] = True
|
|
|
|
|
|
|
|
if context and context.get('active_ids'):
|
|
|
|
# Browse the selected objects via their reference in context
|
|
|
|
model = context.get('active_model') or context.get('model')
|
|
|
|
objects_model = self.pool[model]
|
|
|
|
objects = objects_model.browse(cr, uid, context['active_ids'], context=context)
|
|
|
|
else:
|
|
|
|
# If no context is set (for instance, during test execution), build one
|
|
|
|
model = self.pool['report']._get_report_from_name(cr, uid, self._template).model
|
|
|
|
objects_model = self.pool[model]
|
|
|
|
objects = objects_model.browse(cr, uid, ids, context=context)
|
|
|
|
context['active_model'] = model
|
|
|
|
context['active_ids'] = ids
|
|
|
|
|
|
|
|
# Generate the old style report
|
|
|
|
wrapped_report = self._wrapped_report_class(cr, uid, '', context=context)
|
2014-04-03 15:48:56 +00:00
|
|
|
wrapped_report.set_context(objects, data, context['active_ids'])
|
2014-04-02 16:23:44 +00:00
|
|
|
|
|
|
|
# Rendering self._template with the wrapped report instance localcontext as
|
|
|
|
# rendering environment
|
[FIX] report: abstract reports default lang
In ir_ui_view.py, in method render (line 132 atm),
the values passed to the rendering engine is a merge of the context
and the values.
Therefore, if at this place, the language is rightly set in the context,
the report lang will be as well in the values.
In abstract_report.py, the values passed to the render method is the
wrapped report localcontext in which are added some key/values
(docs, doc_ids, doc_model).
By default, the lang in the localcontext is False
See __init__ method of rml_parse class in report_sxw.py.
If setLang method is not called, the lang in the localcontext remains False.
In this rev., we avoid to overwrite the lang from the context by the lang
of the localcontext if this one is False, so the lang of the report is set
with the current context lang.
Forcing the lang of the report to False had as side-effect to prevent the
editing of report using the website editor(e.g. playslip_report)
opw-628720
2015-02-24 16:33:35 +00:00
|
|
|
docargs = dict(wrapped_report.localcontext)
|
|
|
|
if not docargs.get('lang'):
|
|
|
|
docargs.pop('lang', False)
|
2014-04-02 16:23:44 +00:00
|
|
|
docargs['docs'] = docargs.get('objects')
|
2014-04-03 14:32:35 +00:00
|
|
|
|
2014-04-22 12:11:05 +00:00
|
|
|
# Used in template translation (see translate_doc method from report model)
|
2014-04-03 14:32:35 +00:00
|
|
|
docargs['doc_ids'] = context['active_ids']
|
|
|
|
docargs['doc_model'] = model
|
|
|
|
|
2014-04-02 16:23:44 +00:00
|
|
|
return self.pool['report'].render(cr, uid, [], self._template, docargs, context=context)
|