1
# -*- coding: utf-8 -*-
2
##############################################################################
4
# OpenERP, Account Force Period Close
5
# Copyright (C) 2013 Enterprise Objects Consulting
6
# http://www.eoconsulting.com.ar
7
# Authors: Mariano Ruiz <mrsarm@gmail.com>
9
# This program is free software: you can redistribute it and/or modify
10
# it under the terms of the GNU Affero General Public License as
11
# published by the Free Software Foundation, either version 3 of the
12
# License, or (at your option) any later version.
14
# This program is distributed in the hope that it will be useful,
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU Affero General Public License for more details.
19
# You should have received a copy of the GNU Affero General Public License
20
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
##############################################################################
24
from openerp.osv import fields, osv
25
from openerp.tools.translate import _
27
class account_period_close(osv.osv_memory):
28
_inherit = "account.period.close"
30
'force_close': fields.boolean('Force close period',
31
help="Check this if you want to post all account move "
32
"in draft state from this period"),
35
def data_save(self, cr, uid, ids, context=None):
37
This function close period
38
@param cr: the current row, from the database cursor,
39
@param uid: the current user’s ID for security checks,
40
@param ids: account period close’s ID or list of IDs
42
period_pool = self.pool.get('account.period')
43
account_move_obj = self.pool.get('account.move')
46
for form in self.read(cr, uid, ids, context=context):
48
for id in context['active_ids']:
49
account_move_ids = account_move_obj.search(cr, uid, [('period_id', '=', id), ('state', '=', "draft")], context=context)
50
if account_move_ids and not form['force_close']:
51
raise osv.except_osv(_('Invalid action !'), _('In order to close a period, you must first post related journal entries.'))
53
account_move_obj.button_validate(cr, uid, account_move_ids, context)
55
cr.execute('update account_journal_period set state=%s where period_id=%s', (mode, id))
56
cr.execute('update account_period set state=%s where id=%s', (mode, id))
58
# Log message for Period
59
for period_id, name in period_pool.name_get(cr, uid, [id]):
60
period_pool.log(cr, uid, period_id, "Period '%s' is closed, no more modification allowed for this period." % (name))
61
return {'type': 'ir.actions.act_window_close'}
63
account_period_close()