[FIX] account: several fixes on the new bank statement reconciliation widget
[odoo/odoo.git] / addons / account / wizard / account_move_line_select.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 class account_move_line_select(osv.osv_memory):
25     """
26         Account move line select
27     """
28     _name = "account.move.line.select"
29     _description = "Account move line select"
30
31     def open_window(self, cr, uid, ids, context=None):
32         mod_obj = self.pool.get('ir.model.data')
33         act_obj = self.pool.get('ir.actions.act_window')
34         account_obj = self.pool.get('account.account')
35         fiscalyear_obj = self.pool.get('account.fiscalyear')
36
37         if context is None:
38             context = {}
39
40         if 'fiscalyear' not in context:
41             fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
42         else:
43             fiscalyear_ids = [context['fiscalyear']]
44
45         fiscalyears = fiscalyear_obj.browse(cr, uid, fiscalyear_ids, context=context)
46
47         period_ids = []
48         if fiscalyears:
49             for fiscalyear in fiscalyears:
50                 for period in fiscalyear.period_ids:
51                     period_ids.append(period.id)
52             domain = str(('period_id', 'in', period_ids))
53
54         result = mod_obj.get_object_reference(cr, uid, 'account', 'action_move_line_tree1')
55         id = result and result[1] or False
56         result = act_obj.read(cr, uid, [id])[0]
57         result['context'] = {
58             'fiscalyear': False,
59             'account_id': context['active_id'],
60             'active_id': context['active_id'],
61         }
62
63         if context['active_id']:
64             acc_data = account_obj.browse(cr, uid, context['active_id']).child_consol_ids
65             if acc_data:
66                 result['context'].update({'consolidate_children': True})
67         result['domain']=result['domain'][0:-1]+','+domain+result['domain'][-1]
68         return result
69
70
71 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: