[MERGE] fix: do not reinvoice customer invoices
[odoo/odoo.git] / addons / document / directory_report.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
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.
12 #
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.
17 #
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/>.
20 #
21 ##############################################################################
22
23 from osv import osv, fields
24
25 class ir_action_report_xml(osv.osv):
26     _name="ir.actions.report.xml"
27     _inherit ="ir.actions.report.xml"
28
29     def _model_get(self, cr, uid, ids, name, arg, context=None):
30         res = {}
31         model_pool = self.pool.get('ir.model')
32         for data in self.read(cr, uid, ids, ['model']):
33             model = data.get('model',False)
34             if model:
35                 model_id =model_pool.search(cr, uid, [('model','=',model)])
36                 if model_id:
37                     res[data.get('id')] = model_id[0]
38                 else:
39                     res[data.get('id')] = False
40         return res
41
42     def _model_search(self, cr, uid, obj, name, args, context=None):
43         if not len(args):
44             return []
45         assert len(args) == 1 and args[0][1] == '=', 'expression is not what we expect: %r' % args
46         model_id= args[0][2]
47         if not model_id:
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
51             return []
52         model = self.pool.get('ir.model').read(cr, uid, [model_id])[0]['model']
53         report_id = self.search(cr, uid, [('model','=',model)])
54         if not report_id:
55             return [('id','=','0')]
56         return [('id','in',report_id)]
57
58     _columns={
59         'model_id' : fields.function(_model_get, fnct_search=_model_search, string='Model Id'),
60     }
61
62 ir_action_report_xml()
63
64 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: