~eoc/openobject-addons/eoc-extra-addons-quotation_report

« back to all changes in this revision

Viewing changes to account_force_period_close/wizard/account_period_close.py

  • Committer: Mariano Ruiz
  • Date: 2013-11-08 22:11:24 UTC
  • Revision ID: mrsarm@gmail.com-20131108221124-1ycwelsav4bfl1xh
[IMP] [account_force_period_close] Add new module 'Account Force Period Close'

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
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>
 
8
#
 
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.
 
13
#
 
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.
 
18
#
 
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/>.
 
21
#
 
22
##############################################################################
 
23
 
 
24
from openerp.osv import fields, osv
 
25
from openerp.tools.translate import _
 
26
 
 
27
class account_period_close(osv.osv_memory):
 
28
    _inherit = "account.period.close"
 
29
    _columns = {
 
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"),
 
33
    }
 
34
 
 
35
    def data_save(self, cr, uid, ids, context=None):
 
36
        """
 
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
 
41
         """
 
42
        period_pool = self.pool.get('account.period')
 
43
        account_move_obj = self.pool.get('account.move')
 
44
 
 
45
        mode = 'done'
 
46
        for form in self.read(cr, uid, ids, context=context):
 
47
            if form['sure']:
 
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.'))
 
52
                    else:
 
53
                        account_move_obj.button_validate(cr, uid, account_move_ids, context)
 
54
 
 
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))
 
57
 
 
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'}
 
62
 
 
63
account_period_close()