[MERGE] merge from dev3
[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 osv import osv, fields
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),
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 line in self.browse(cr, uid, ids):
37             # Todo: if there is not internal seq defined on journal raise error ?
38             if line.journal_id.internal_sequence:
39                 seq_no = obj_sequence.get_id(cr, uid, line.journal_id.internal_sequence.id, context=context)
40             if seq_no:
41                 self.write(cr, uid, [line.id], {'internal_sequence_number': seq_no})
42         return res
43
44 account_move()
45
46 class account_journal(osv.osv):
47     _inherit = "account.journal"
48
49     _columns = {
50         'internal_sequence': fields.many2one('ir.sequence', 'Internal Sequence'),
51     }
52
53 account_journal()
54
55 class account_move_line(osv.osv):
56     _inherit = "account.move.line"
57
58     _columns = {
59         'internal_sequence_number': fields.related('move_id','internal_sequence_number', type='char', relation='account.move', string='Internal Number'),
60     }
61 account_move_line()
62
63 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: