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

« back to all changes in this revision

Viewing changes to account_force_period_close/account.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 osv
 
25
from openerp.tools.translate import _
 
26
 
 
27
class account_move(osv.osv):
 
28
    _inherit = "account.move"
 
29
 
 
30
    def post(self, cr, uid, ids, context=None):
 
31
        """
 
32
        This method is overridden only to FIX
 
33
        a BUG in the validation
 
34
        """
 
35
        ## Bug Fix
 
36
        if isinstance(ids, (list,tuple)) and len(ids)==0:
 
37
            return True
 
38
        ## End Fix
 
39
        if context is None:
 
40
            context = {}
 
41
        invoice = context.get('invoice', False)
 
42
        valid_moves = self.validate(cr, uid, ids, context)
 
43
 
 
44
        if not valid_moves:
 
45
            raise osv.except_osv(_('Integrity Error !'), _('You can not validate a non-balanced entry !\nMake sure you have configured payment terms properly !\nThe latest payment term line should be of the type "Balance" !'))
 
46
        obj_sequence = self.pool.get('ir.sequence')
 
47
        for move in self.browse(cr, uid, valid_moves, context=context):
 
48
            if move.name =='/':
 
49
                new_name = False
 
50
                journal = move.journal_id
 
51
 
 
52
                if invoice and invoice.internal_number:
 
53
                    new_name = invoice.internal_number
 
54
                else:
 
55
                    if journal.sequence_id:
 
56
                        c = {'fiscalyear_id': move.period_id.fiscalyear_id.id}
 
57
                        new_name = obj_sequence.next_by_id(cr, uid, journal.sequence_id.id, c)
 
58
                    else:
 
59
                        raise osv.except_osv(_('Error'), _('No sequence defined on the journal !'))
 
60
 
 
61
                if new_name:
 
62
                    self.write(cr, uid, [move.id], {'name':new_name})
 
63
 
 
64
        cr.execute('UPDATE account_move '\
 
65
                   'SET state=%s '\
 
66
                   'WHERE id IN %s',
 
67
                   ('posted', tuple(valid_moves),))
 
68
        return True
 
69
 
 
70
account_move()