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 osv
25
from openerp.tools.translate import _
27
class account_move(osv.osv):
28
_inherit = "account.move"
30
def post(self, cr, uid, ids, context=None):
32
This method is overridden only to FIX
33
a BUG in the validation
36
if isinstance(ids, (list,tuple)) and len(ids)==0:
41
invoice = context.get('invoice', False)
42
valid_moves = self.validate(cr, uid, ids, context)
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):
50
journal = move.journal_id
52
if invoice and invoice.internal_number:
53
new_name = invoice.internal_number
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)
59
raise osv.except_osv(_('Error'), _('No sequence defined on the journal !'))
62
self.write(cr, uid, [move.id], {'name':new_name})
64
cr.execute('UPDATE account_move '\
67
('posted', tuple(valid_moves),))