[IMP] removal of usages of the deprecated node.getchildren call, better usage of...
[odoo/odoo.git] / addons / account / sequence.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 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
24 from osv import fields,osv
25
26 class ir_sequence_fiscalyear(osv.osv):
27     _name = 'account.sequence.fiscalyear'
28     _rec_name = "sequence_main_id"
29     _columns = {
30         "sequence_id": fields.many2one("ir.sequence", 'Sequence', required=True, ondelete='cascade'),
31         "sequence_main_id": fields.many2one("ir.sequence", 'Main Sequence', required=True, ondelete='cascade'),
32         "fiscalyear_id": fields.many2one('account.fiscalyear', 'Fiscal Year', required=True, ondelete='cascade')
33     }
34 ir_sequence_fiscalyear()
35
36 class ir_sequence(osv.osv):
37     _inherit = 'ir.sequence'
38     _columns = {
39         'fiscal_ids' : fields.one2many('account.sequence.fiscalyear', 'sequence_main_id', 'Sequences')
40     }
41     def get_id(self, cr, uid, sequence_id, test='id=%s', context={}):
42         cr.execute('select id from ir_sequence where '+test+' and active=%s', (sequence_id, True,))
43         res = cr.dictfetchone()
44         if res:
45             for line in self.browse(cr, uid, res['id'], context=context).fiscal_ids:
46                 if line.fiscalyear_id.id==context.get('fiscalyear_id', False):
47                     return super(ir_sequence, self).get_id(cr, uid, line.sequence_id.id, test="id=%s", context=context)
48         return super(ir_sequence, self).get_id(cr, uid, sequence_id, test, context)
49 ir_sequence()
50
51
52 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: