1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from openerp.osv import fields, osv
24 class account_sequence_installer(osv.osv_memory):
25 _name = 'account.sequence.installer'
26 _inherit = 'res.config.installer'
29 'name': fields.char('Name',size=64, required=True),
30 'prefix': fields.char('Prefix',size=64, help="Prefix value of the record for the sequence"),
31 'suffix': fields.char('Suffix',size=64, help="Suffix value of the record for the sequence"),
32 'number_next': fields.integer('Next Number', required=True, help="Next number of this sequence"),
33 'number_increment': fields.integer('Increment Number', required=True, help="The next number of the sequence will be incremented by this number"),
34 'padding' : fields.integer('Number padding', required=True, help="OpenERP will automatically adds some '0' on the left of the 'Next Number' to get the required padding size."),
35 'company_id': fields.many2one('res.company', 'Company'),
38 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'ir.sequence', context=c),
39 'number_increment': 1,
42 'name': 'Internal Sequence Journal',
45 def execute(self, cr, uid, ids, context=None):
48 record = self.browse(cr, uid, ids, context=context)[0]
51 company_id = record.company_id.id,
52 search_criteria = [('company_id', '=', company_id)]
57 'id': 'internal_sequence_journal',
58 'code': 'account.journal',
60 'prefix': record.prefix,
61 'suffix': record.suffix,
62 'number_next': record.number_next,
63 'number_increment': record.number_increment,
64 'padding' : record.padding,
65 'company_id': company_id,
68 obj_sequence = self.pool.get('ir.sequence')
69 ir_seq = obj_sequence.create(cr, uid, vals, context)
70 res = super(account_sequence_installer, self).execute(cr, uid, ids, context=context)
71 jou_obj = self.pool.get('account.journal')
72 journal_ids = jou_obj.search(cr, uid, search_criteria, context=context)
73 for journal in jou_obj.browse(cr, uid, journal_ids, context=context):
74 if not journal.internal_sequence_id:
75 j_ids.append(journal.id)
77 jou_obj.write(cr, uid, j_ids, {'internal_sequence_id': ir_seq})
78 ir_values_obj = self.pool.get('ir.values')
79 ir_values_obj.set(cr, uid, key='default', key2=False, name='internal_sequence_id', models =[('account.journal', False)], value=ir_seq)
83 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: