diff --git a/openerp/addons/base/ir/ir_sequence.py b/openerp/addons/base/ir/ir_sequence.py index 0f505814c0c..9e9e0696cbe 100644 --- a/openerp/addons/base/ir/ir_sequence.py +++ b/openerp/addons/base/ir/ir_sequence.py @@ -198,7 +198,7 @@ class ir_sequence(openerp.osv.osv.osv): if new_implementation in ('standard', None): # Implementation has NOT changed. # Only change sequence if really requested. - if row['number_next'] != n: + if values.get('number_next'): self._alter_sequence(cr, row['id'], i, n) else: # Just in case only increment changed diff --git a/openerp/addons/base/tests/__init__.py b/openerp/addons/base/tests/__init__.py index 3c6029c49ea..d1438de25f7 100644 --- a/openerp/addons/base/tests/__init__.py +++ b/openerp/addons/base/tests/__init__.py @@ -6,6 +6,7 @@ import test_ir_values import test_menu import test_search import test_views +import test_ir_sequence checks = [ test_base, @@ -16,4 +17,5 @@ checks = [ test_menu, test_search, test_views, + test_ir_sequence, ] diff --git a/openerp/addons/base/tests/test_ir_sequence.py b/openerp/addons/base/tests/test_ir_sequence.py new file mode 100644 index 00000000000..85ae21bb8cc --- /dev/null +++ b/openerp/addons/base/tests/test_ir_sequence.py @@ -0,0 +1,35 @@ +import unittest2 + +import openerp.tests.common as common + + +class Test_ir_sequence(common.TransactionCase): + + def test_00(self): + registry, cr, uid = self.registry, self.cr, self.uid + + # test if read statement return the good number_next value (from postgreSQL sequence and not ir_sequence value) + sequence = registry('ir.sequence') + # first creation of sequence (normal) + values = {'number_next': 1, + 'company_id': 1, + 'padding': 4, + 'number_increment': 1, + 'implementation': 'standard', + 'name': 'test-sequence-00'} + seq_id = sequence.create(cr, uid, values) + # Call get next 4 times + sequence.next_by_id(cr, uid, seq_id) + sequence.next_by_id(cr, uid, seq_id) + sequence.next_by_id(cr, uid, seq_id) + read_sequence = sequence.next_by_id(cr, uid, seq_id) + # Read the value of the current sequence + assert read_sequence == "0004", 'The actual sequence value must be 4. reading : %s' % read_sequence + # reset sequence to 1 by write method calling + sequence.write(cr, uid, [seq_id], {'number_next': 1}) + # Read the value of the current sequence + read_sequence = sequence.next_by_id(cr, uid, seq_id) + assert read_sequence == "0001", 'The actual sequence value must be 1. reading : %s' % read_sequence + +if __name__ == "__main__": + unittest2.main()