2010-03-30 12:47:02 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
##############################################################################
|
|
|
|
|
#
|
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
|
# 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.
|
|
|
|
|
#
|
|
|
|
|
# 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
|
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
|
|
|
|
from osv import fields, osv
|
2011-12-09 09:48:44 +00:00
|
|
|
|
from tools.translate import _
|
2010-03-30 12:47:02 +00:00
|
|
|
|
|
|
|
|
|
class account_period_close(osv.osv_memory):
|
|
|
|
|
"""
|
|
|
|
|
close period
|
|
|
|
|
"""
|
|
|
|
|
_name = "account.period.close"
|
|
|
|
|
_description = "period close"
|
|
|
|
|
_columns = {
|
2010-04-06 07:27:56 +00:00
|
|
|
|
'sure': fields.boolean('Check this box'),
|
2010-08-19 11:51:57 +00:00
|
|
|
|
}
|
2010-03-30 12:47:02 +00:00
|
|
|
|
|
2010-04-29 06:35:55 +00:00
|
|
|
|
def data_save(self, cr, uid, ids, context=None):
|
2010-03-30 12:47:02 +00:00
|
|
|
|
"""
|
|
|
|
|
This function close period
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
|
|
|
|
@param ids: account period close’s ID or list of IDs
|
|
|
|
|
"""
|
2010-10-15 13:35:22 +00:00
|
|
|
|
period_pool = self.pool.get('account.period')
|
2011-12-09 09:48:44 +00:00
|
|
|
|
account_move_obj = self.pool.get('account.move')
|
2010-03-30 12:47:02 +00:00
|
|
|
|
|
|
|
|
|
mode = 'done'
|
2010-04-29 06:35:55 +00:00
|
|
|
|
for form in self.read(cr, uid, ids, context=context):
|
2010-03-30 12:47:02 +00:00
|
|
|
|
if form['sure']:
|
|
|
|
|
for id in context['active_ids']:
|
2011-12-09 09:52:22 +00:00
|
|
|
|
account_move_ids = account_move_obj.search(cr, uid, [('period_id', '=', id), ('state', '=', "draft")], context=context)
|
2011-12-09 09:48:44 +00:00
|
|
|
|
if account_move_ids:
|
2012-08-07 11:06:16 +00:00
|
|
|
|
raise osv.except_osv(_('Invalid Action!'), _('In order to close a period, you must first post related journal entries.'))
|
2011-12-09 09:48:44 +00:00
|
|
|
|
|
2010-03-30 12:47:02 +00:00
|
|
|
|
cr.execute('update account_journal_period set state=%s where period_id=%s', (mode, id))
|
|
|
|
|
cr.execute('update account_period set state=%s where id=%s', (mode, id))
|
2010-07-22 07:30:45 +00:00
|
|
|
|
|
2010-12-28 10:44:45 +00:00
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
2010-03-30 12:47:02 +00:00
|
|
|
|
|
|
|
|
|
account_period_close()
|
|
|
|
|
|
2012-06-13 09:06:00 +00:00
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|