summaryrefslogtreecommitdiff
path: root/addons/account_sequence/account_sequence_installer.py
diff options
context:
space:
mode:
authoruco (OpenERP) <uco@tinyerp.com>2010-12-06 18:41:02 +0530
committeruco (OpenERP) <uco@tinyerp.com>2010-12-06 18:41:02 +0530
commitb1cf433ecc01a58c8abe27fdf9dbaba2deedf7f5 (patch)
tree7d4b2df75b76c3529854cf98c401ad59370ce00a /addons/account_sequence/account_sequence_installer.py
parenteb04af83f31615e220a1b5e9639e799eb88242d6 (diff)
parent5350ab0c1930e6573ee52bd430bb1d0f5adea2a3 (diff)
[MERGE]: Merged with trunk-addons.
bzr revid: uco@tinyerp.com-20101206131102-z2xzz8eshkswo00q
Diffstat (limited to 'addons/account_sequence/account_sequence_installer.py')
-rw-r--r--addons/account_sequence/account_sequence_installer.py83
1 files changed, 83 insertions, 0 deletions
diff --git a/addons/account_sequence/account_sequence_installer.py b/addons/account_sequence/account_sequence_installer.py
new file mode 100644
index 00000000000..f7bcb113388
--- /dev/null
+++ b/addons/account_sequence/account_sequence_installer.py
@@ -0,0 +1,83 @@
+# -*- coding: utf-8 -*-
+##############################################################################
+#
+# OpenERP, Open Source Management Solution
+# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+##############################################################################
+
+from osv import fields, osv
+
+class account_sequence_installer(osv.osv_memory):
+ _name = 'account.sequence.installer'
+ _inherit = 'res.config.installer'
+
+ _columns = {
+ 'name': fields.char('Name',size=64, required=True),
+ 'prefix': fields.char('Prefix',size=64, help="Prefix value of the record for the sequence"),
+ 'suffix': fields.char('Suffix',size=64, help="Suffix value of the record for the sequence"),
+ 'number_next': fields.integer('Next Number', required=True, help="Next number of this sequence"),
+ 'number_increment': fields.integer('Increment Number', required=True, help="The next number of the sequence will be incremented by this number"),
+ '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."),
+ 'company_id': fields.many2one('res.company', 'Company'),
+ }
+ _defaults = {
+ 'company_id': lambda s,cr,uid,c: s.pool.get('res.company')._company_default_get(cr, uid, 'ir.sequence', context=c),
+ 'number_increment': 1,
+ 'number_next': 1,
+ 'padding' : 0,
+ 'name': 'Internal Sequence Journal',
+ }
+
+ def execute(self, cr, uid, ids, context=None):
+ if context is None:
+ context = {}
+ jou_obj = self.pool.get('account.journal')
+ obj_sequence = self.pool.get('ir.sequence')
+ record = self.browse(cr, uid, ids, context)[0]
+ j_ids = []
+ if record.company_id:
+ company_id = record.company_id.id,
+ search_criteria = [('company_id', '=', company_id)]
+ else:
+ company_id = False
+ search_criteria = []
+ vals = {
+ 'id': 'internal_sequence_journal',
+ 'code': 'account.journal',
+ 'name': record.name,
+ 'prefix': record.prefix,
+ 'suffix': record.suffix,
+ 'number_next': record.number_next,
+ 'number_increment': record.number_increment,
+ 'padding' : record.padding,
+ 'company_id': company_id,
+ }
+
+ ir_seq = obj_sequence.create(cr, uid, vals, context)
+ res = super(account_sequence_installer, self).execute(cr, uid, ids, context=context)
+ journal_ids = jou_obj.search(cr, uid, search_criteria, context=context)
+ for journal in jou_obj.browse(cr, uid, journal_ids, context):
+ if not journal.internal_sequence_id:
+ j_ids.append(journal.id)
+ if j_ids:
+ jou_obj.write(cr, uid, j_ids, {'internal_sequence_id': ir_seq})
+ self.pool.get('ir.values').set(cr, uid, key='default', key2=False, name='internal_sequence_id', models =[('account.journal', False)], value=ir_seq)
+ return res
+
+account_sequence_installer()
+
+# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: