diff --git a/account_auto_fy_sequence/README.rst b/account_auto_fy_sequence/README.rst index 24fead8ae..300a775f5 100644 --- a/account_auto_fy_sequence/README.rst +++ b/account_auto_fy_sequence/README.rst @@ -8,6 +8,9 @@ using the sequence. The first time the sequence is used for a given fiscal year, a specific fiscal year sequence starting at 1 is created automatically. +The module also replaces %(year)s by %(fy)s in the default prefix +for new journals, assuming it is a safer default. + Caveat ------ @@ -27,4 +30,4 @@ Author: Contributors: -* Laetitia Gangloff (ACSONE) \ No newline at end of file +* Laetitia Gangloff (ACSONE) diff --git a/account_auto_fy_sequence/models/__init__.py b/account_auto_fy_sequence/models/__init__.py index 8833fa6e1..11c049809 100644 --- a/account_auto_fy_sequence/models/__init__.py +++ b/account_auto_fy_sequence/models/__init__.py @@ -24,3 +24,4 @@ ############################################################################## from . import ir_sequence +from . import account_journal diff --git a/account_auto_fy_sequence/models/account_journal.py b/account_auto_fy_sequence/models/account_journal.py new file mode 100644 index 000000000..7f651e0ad --- /dev/null +++ b/account_auto_fy_sequence/models/account_journal.py @@ -0,0 +1,43 @@ +# coding=utf-8 +############################################################################## +# +# account_auto_fy_sequence module for Odoo +# Copyright (C) 2014 ACSONE SA/NV () +# @author Laetitia Gangloff +# +# account_auto_fy_sequence is free software: +# you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License v3 or later +# as published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# account_auto_fy_sequence 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 v3 or later for more details. +# +# You should have received a copy of the GNU Affero General Public License +# v3 or later along with this program. +# If not, see . +# +############################################################################## + +from openerp.osv import orm + + +class account_journal(orm.Model): + _inherit = "account.journal" + + def create_sequence(self, cr, uid, vals, context=None): + """ Create new no_gap entry sequence for every new Joural + with fiscal year prefix + """ + seq_id = super(account_journal, self).create_sequence(cr, uid, vals, + context=context) + + seq_obj = self.pool['ir.sequence'] + seq = seq_obj.browse(cr, uid, seq_id, context=context) + prefix = seq.prefix.replace('%(year)s', '%(fy)s') + seq_obj.write(cr, uid, seq_id, {'prefix': prefix}, context=context) + return seq_id diff --git a/account_auto_fy_sequence/tests/test_auto_fy_sequence.py b/account_auto_fy_sequence/tests/test_auto_fy_sequence.py index 235822ca7..a4a57ed6b 100644 --- a/account_auto_fy_sequence/tests/test_auto_fy_sequence.py +++ b/account_auto_fy_sequence/tests/test_auto_fy_sequence.py @@ -67,3 +67,13 @@ class TestAutoFYSequence(common.TransactionCase): self.assertEqual(n, "SEQ/%s/1" % fiscalyear.code) n = self.seq_obj._next(self.cr, self.uid, [seq_id], context) self.assertEqual(n, "SEQ/%s/2" % fiscalyear.code) + + def test_3(self): + """ Create journal and check the sequence attached to the journal """ + aj_obj = self.registry('account.journal') + aj_id = aj_obj.create(self.cr, self.uid, {'name': 'sequence (test)', + 'code': 'SQT', + 'type': 'bank', + }) + aj = aj_obj.browse(self.cr, self.uid, aj_id) + self.assertEqual(aj.sequence_id.prefix, 'SQT/%(fy)s/')