1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU Affero General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU Affero General Public License for more details.
18 # You should have received a copy of the GNU Affero General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from osv import osv, fields
25 class ir_action_report_xml(osv.osv):
26 _name="ir.actions.report.xml"
27 _inherit ="ir.actions.report.xml"
29 def _model_get(self, cr, uid, ids, name, arg, context=None):
31 model_pool = self.pool.get('ir.model')
32 for data in self.read(cr, uid, ids, ['model']):
33 model = data.get('model',False)
35 model_id =model_pool.search(cr, uid, [('model','=',model)])
37 res[data.get('id')] = model_id[0]
39 res[data.get('id')] = False
42 def _model_search(self, cr, uid, obj, name, args, context=None):
45 assert len(args) == 1 and args[0][1] == '=', 'expression is not what we expect: %r' % args
48 # a deviation from standard behavior: when searching model_id = False
49 # we return *all* reports, not just ones with empty model.
50 # One reason is that 'model' is a required field so far
52 model = self.pool.get('ir.model').read(cr, uid, [model_id])[0]['model']
53 report_id = self.search(cr, uid, [('model','=',model)])
55 return [('id','=','0')]
56 return [('id','in',report_id)]
59 'model_id' : fields.function(_model_get, fnct_search=_model_search, method=True, string='Model Id'),
62 ir_action_report_xml()