ec938f0349f31f77e86a81cc64592d2d743bf02f
[odoo/odoo.git] / addons / account / wizard / account_validate_account_move.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 from openerp.osv import fields, osv
22 from openerp.tools.translate import _
23
24 class validate_account_move(osv.osv_memory):
25     _name = "validate.account.move"
26     _description = "Validate Account Move"
27     _columns = {
28         'journal_id': fields.many2many('account.journal', 'wizard_validate_account_move_journal', 'wizard_id', 'journal_id', 'Journal', required=True),
29         'period_id': fields.many2many('account.period', 'wizard_validate_account_move_period', 'wizard_id', 'period_id', 'Period', required=True, domain=[('state','<>','done')]),
30     }
31
32     def validate_move(self, cr, uid, ids, context=None):
33         obj_move = self.pool.get('account.move')
34         if context is None:
35             context = {}
36         data = self.read(cr, uid, ids[0], context=context)
37         ids_move = obj_move.search(cr, uid, [('state','=','draft'),('journal_id','in',tuple(data['journal_id'])),('period_id','in',tuple(data['period_id']))])
38         if not ids_move:
39             raise osv.except_osv(_('Warning!'), _('Specified journals do not have any account move entries in draft state for the specified periods.'))
40         obj_move.button_validate(cr, uid, ids_move, context=context)
41         return {'type': 'ir.actions.act_window_close'}
42
43 validate_account_move()
44
45 class validate_account_move_lines(osv.osv_memory):
46     _name = "validate.account.move.lines"
47     _description = "Validate Account Move Lines"
48
49     def validate_move_lines(self, cr, uid, ids, context=None):
50         obj_move_line = self.pool.get('account.move.line')
51         obj_move = self.pool.get('account.move')
52         move_ids = []
53         if context is None:
54             context = {}
55         data_line = obj_move_line.browse(cr, uid, context['active_ids'], context)
56         for line in data_line:
57             if line.move_id.state=='draft':
58                 move_ids.append(line.move_id.id)
59         move_ids = list(set(move_ids))
60         if not move_ids:
61             raise osv.except_osv(_('Warning!'), _('Selected Entry Lines does not have any account move entries in draft state.'))
62         obj_move.button_validate(cr, uid, move_ids, context)
63         return {'type': 'ir.actions.act_window_close'}
64 validate_account_move_lines()
65
66 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
67