1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2014-Today OpenERP SA (<http://www.openerp.com>).
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.
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.
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/>.
20 ##############################################################################
22 from openerp.osv import osv
25 class AbstractReport(osv.AbstractModel):
26 """Model used to embed old style reports"""
27 _name = 'report.abstract_report'
29 _wrapped_report_class = None
31 def render_html(self, cr, uid, ids, data=None, context=None):
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
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)
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
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'])
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')
61 # Used in template translating (see render_doc method from report model)
62 docargs['doc_ids'] = context['active_ids']
63 docargs['doc_model'] = model
65 return self.pool['report'].render(cr, uid, [], self._template, docargs, context=context)