[MERGE] forward port of branch 7.0 up to 3a0af6a
[odoo/odoo.git] / addons / account_sequence / account_sequence.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU General Public License for more details.
17 #
18 #    You should have received a copy of the GNU General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 from openerp.osv import fields, osv
24
25 class account_move(osv.osv):
26     _inherit = 'account.move'
27
28     _columns = {
29         'internal_sequence_number': fields.char('Internal Number', size=64, readonly=True, help='Internal Sequence Number'),
30     }
31
32     def post(self, cr, uid, ids, context=None):
33         obj_sequence = self.pool.get('ir.sequence')
34         res = super(account_move, self).post(cr, uid, ids, context=context)
35         seq_no = False
36         for move in self.browse(cr, uid, ids, context=context):
37             if move.journal_id.internal_sequence_id:
38                 seq_no = obj_sequence.next_by_id(cr, uid, move.journal_id.internal_sequence_id.id, context=context)
39             if seq_no:
40                 self.write(cr, uid, [move.id], {'internal_sequence_number': seq_no})
41         return res
42
43
44 class account_journal(osv.osv):
45     _inherit = "account.journal"
46
47     _columns = {
48         'internal_sequence_id': fields.many2one('ir.sequence', 'Internal Sequence', help="This sequence will be used to maintain the internal number for the journal entries related to this journal."),
49     }
50
51
52 class account_move_line(osv.osv):
53     _inherit = "account.move.line"
54
55     _columns = {
56         'internal_sequence_number': fields.related('move_id','internal_sequence_number', type='char', relation='account.move', help='Internal Sequence Number', string='Internal Number'),
57     }
58
59
60 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: