2009-10-13 05:58:37 +00:00
# -*- coding: utf-8 -*-
2008-06-04 12:42:36 +00:00
##############################################################################
2009-11-25 09:31:44 +00:00
#
2009-10-14 11:15:34 +00:00
# OpenERP, Open Source Management Solution
2010-01-12 09:18:39 +00:00
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
2008-06-16 11:00:21 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is free software: you can redistribute it and/or modify
2009-10-14 11:15:34 +00:00
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
2008-06-04 12:42:36 +00:00
#
2008-11-03 19:18:56 +00:00
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2009-10-14 11:15:34 +00:00
# GNU Affero General Public License for more details.
2008-06-04 12:42:36 +00:00
#
2009-10-14 11:15:34 +00:00
# You should have received a copy of the GNU Affero General Public License
2009-11-25 09:31:44 +00:00
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2008-06-04 12:42:36 +00:00
#
##############################################################################
import wizard
from osv import osv
import pooler
2008-07-08 08:13:12 +00:00
from tools . translate import _
2008-06-04 12:42:36 +00:00
_journal_form = ''' <?xml version= " 1.0 " ?>
2008-09-02 13:26:51 +00:00
< form string = " Validate Account Entries " >
< separator string = " Select Period and Journal for Validation " colspan = " 4 " / >
2008-07-22 15:11:28 +00:00
< field name = " journal_id " / >
< newline / >
< field name = " period_id " / >
2008-09-02 13:26:51 +00:00
< separator string = " Information " colspan = " 4 " / >
< label string = " All draft account entries in this journal and period will be validated. It means you won ' t be able to modify their accouting fields. " colspan = " 4 " / >
2008-06-04 12:42:36 +00:00
< / form > '''
2008-06-17 06:40:30 +00:00
2008-06-04 12:42:36 +00:00
_journal_fields = {
2008-07-22 15:11:28 +00:00
' journal_id ' : { ' string ' : ' Journal ' , ' type ' : ' many2one ' , ' relation ' : ' account.journal ' , ' required ' : True } ,
' period_id ' : { ' string ' : ' Period ' , ' type ' : ' many2one ' , ' relation ' : ' account.period ' , ' required ' : True , ' domain ' : " [( ' state ' , ' <> ' , ' done ' )] " } ,
2008-06-04 12:42:36 +00:00
}
def _validate_move ( self , cr , uid , data , context = { } ) :
2008-07-22 15:11:28 +00:00
pool = pooler . get_pool ( cr . dbname )
move_obj = pool . get ( ' account.move ' )
ids_move = move_obj . search ( cr , uid , [ ( ' state ' , ' = ' , ' draft ' ) , ( ' journal_id ' , ' = ' , data [ ' form ' ] [ ' journal_id ' ] ) , ( ' period_id ' , ' = ' , data [ ' form ' ] [ ' period_id ' ] ) ] )
if not ids_move :
raise wizard . except_wizard ( _ ( ' Warning ' ) , _ ( ' Specified Journal does not have any account move entries in draft state for this period ' ) )
res = move_obj . button_validate ( cr , uid , ids_move , context )
return { }
2008-06-04 12:42:36 +00:00
class validate_account_move ( wizard . interface ) :
2008-07-22 15:11:28 +00:00
states = {
' init ' : {
' actions ' : [ ] ,
' result ' : { ' type ' : ' form ' , ' arch ' : _journal_form , ' fields ' : _journal_fields , ' state ' : [ ( ' end ' , ' Cancel ' ) , ( ' validate ' , ' Validate ' ) ] }
} ,
' validate ' : {
' actions ' : [ _validate_move ] ,
' result ' : { ' type ' : ' state ' , ' state ' : ' end ' }
} ,
}
2008-06-04 12:42:36 +00:00
validate_account_move ( ' account.move.validate ' )
def _validate_move_lines ( self , cr , uid , data , context = { } ) :
2008-07-22 15:11:28 +00:00
move_ids = [ ]
pool = pooler . get_pool ( cr . dbname )
move_line_obj = pool . get ( ' account.move.line ' )
move_obj = pool . get ( ' account.move ' )
data_line = move_line_obj . browse ( cr , uid , data [ ' ids ' ] , context )
for line in data_line :
if line . move_id . state == ' draft ' :
move_ids . append ( line . move_id . id )
move_ids = list ( set ( move_ids ) )
if not move_ids :
2009-11-25 09:31:44 +00:00
raise wizard . except_wizard ( _ ( ' Warning ' ) , _ ( ' Selected Entry Lines does not have any account move enties in draft state ' ) )
2008-07-22 15:11:28 +00:00
res = move_obj . button_validate ( cr , uid , move_ids , context )
return { }
2008-06-04 12:42:36 +00:00
class validate_account_move_lines ( wizard . interface ) :
2008-07-22 15:11:28 +00:00
states = {
' init ' : {
' actions ' : [ _validate_move_lines ] ,
' result ' : { ' type ' : ' state ' , ' state ' : ' end ' }
} ,
}
2008-06-17 06:40:30 +00:00
validate_account_move_lines ( ' account.move_line.validate ' )
2008-07-23 14:41:47 +00:00
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: