[FIX] /web/login restore request.uid in case of authentication failure
[odoo/odoo.git] / addons / report / models / abstract_report.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 from openerp.osv import osv
23
24
25 class AbstractReport(osv.AbstractModel):
26     """Model used to embed old style reports"""
27     _name = 'report.abstract_report'
28     _template = None
29     _wrapped_report_class = None
30
31     def render_html(self, cr, uid, ids, data=None, context=None):
32         if context is None:
33             context = {}
34
35         # If the key 'landscape' is present in data['form'], passing it into the context
36         if data and data.get('form', {}).get('landscape'):
37             context['landscape'] = True
38
39         if context and context.get('active_ids'):
40             # Browse the selected objects via their reference in context
41             model = context.get('active_model') or context.get('model')
42             objects_model = self.pool[model]
43             objects = objects_model.browse(cr, uid, context['active_ids'], context=context)
44         else:
45             # If no context is set (for instance, during test execution), build one
46             model = self.pool['report']._get_report_from_name(cr, uid, self._template).model
47             objects_model = self.pool[model]
48             objects = objects_model.browse(cr, uid, ids, context=context)
49             context['active_model'] = model
50             context['active_ids'] = ids
51
52         # Generate the old style report
53         wrapped_report = self._wrapped_report_class(cr, uid, '',  context=context)
54         wrapped_report.set_context(objects, data, context['active_ids'])
55
56         # Rendering self._template with the wrapped report instance localcontext as
57         # rendering environment
58         docargs = wrapped_report.localcontext
59         docargs['docs'] = docargs.get('objects')
60
61         # Used in template translating (see render_doc method from report model)
62         docargs['doc_ids'] = context['active_ids']
63         docargs['doc_model'] = model
64
65         return self.pool['report'].render(cr, uid, [], self._template, docargs, context=context)