1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
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 ##############################################################################
21 from openerp.osv import fields, osv
22 from openerp.tools.translate import _
24 class validate_account_move(osv.osv_memory):
25 _name = "validate.account.move"
26 _description = "Validate Account Move"
28 'journal_id': fields.many2one('account.journal', 'Journal', required=True),
29 'period_id': fields.many2one('account.period', 'Period', required=True, domain=[('state','<>','done')]),
32 def validate_move(self, cr, uid, ids, context=None):
33 obj_move = self.pool.get('account.move')
36 data = self.browse(cr, uid, ids, context=context)[0]
37 ids_move = obj_move.search(cr, uid, [('state','=','draft'),('journal_id','=',data.journal_id.id),('period_id','=',data.period_id.id)])
39 raise osv.except_osv(_('Warning!'), _('Specified journal does not have any account move entries in draft state for this period.'))
40 obj_move.button_validate(cr, uid, ids_move, context=context)
41 return {'type': 'ir.actions.act_window_close'}
43 validate_account_move()
45 class validate_account_move_lines(osv.osv_memory):
46 _name = "validate.account.move.lines"
47 _description = "Validate Account Move Lines"
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')
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))
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()
66 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: