Commit 323627b1 authored by Vincent Pelletier's avatar Vincent Pelletier

FIX decentralised id generator

parent c63ae8e3
......@@ -34,7 +34,7 @@ class IIdGenerator(Interface):
Rounding tool interface
"""
def generateNewId(id_group=None, default=None):
def generateNewId(id_group=None, default=None, poison=False):
"""
Generate the next id in the sequence of ids of a particular group
......@@ -51,9 +51,15 @@ class IIdGenerator(Interface):
If the default value is incompatible with the generator,
ValueError will be raised.
poison (bool)
If True, return the next id in requested sequence, and permanently break
that sequence's state, so that no new id may be successfuly generated
from it. Useful to ensure seamless migration away from this generator,
without risking a (few) late generation from happening after migration
code already moved sequence's state elsewhere.
"""
def generateNewIdList(id_group=None, default=None, id_count=1):
def generateNewIdList(id_group=None, default=None, id_count=1, poison=False):
"""
Generate a list of next ids in the sequence of ids of a particular group
......@@ -75,6 +81,13 @@ class IIdGenerator(Interface):
method should take as parameter the previously generated
id (optional). By default, ids are managed like integers and
are increased one by one
poison (bool)
If True, return the next id in requested sequence, and permanently break
that sequence's state, so that no new id may be successfuly generated
from it. Useful to ensure seamless migration away from this generator,
without risking a (few) late generation from happening after migration
code already moved sequence's state elsewhere.
"""
def initializeGenerator():
......
......@@ -34,7 +34,7 @@ class IIdTool(Interface):
Id Tool interface
"""
def generateNewId(id_group=None, default=None, id_generator=None):
def generateNewId(id_group=None, default=None, id_generator=None, poison=False):
"""
Generate the next id in the sequence of ids of a particular group
......@@ -56,6 +56,13 @@ class IIdTool(Interface):
reference. This is not mandatory, a default generator will exist.
Only id generator of type application can be selected.
poison (bool)
If True, return the next id in requested sequence, and permanently break
that sequence's state, so that no new id may be successfuly generated
from it. Useful to ensure seamless migration away from this generator,
without risking a (few) late generation from happening after migration
code already moved sequence's state elsewhere.
Example :
my_new_id = portal_ids.generateNewId(id_group='sale_invoice',
default=100)
......@@ -63,7 +70,7 @@ class IIdTool(Interface):
"""
def generateNewIdList(id_group=None, default=None, id_count=1,
id_generator=None):
id_generator=None, poison=False):
"""
Generate a list of next ids in the sequence of ids of a particular group
......@@ -85,6 +92,13 @@ class IIdTool(Interface):
reference. This is not mandatory, a default generator will exist.
Only id generator of type application can be selected.
poison (bool)
If True, return the next id in requested sequence, and permanently break
that sequence's state, so that no new id may be successfuly generated
from it. Useful to ensure seamless migration away from this generator,
without risking a (few) late generation from happening after migration
code already moved sequence's state elsewhere.
Example :
my_new_id_list = portal_ids.generateNewIdList(id_group='sale_invoice',
default=100, id_count=3)
......
......@@ -3480,6 +3480,16 @@ class Base( CopyContainer,
return new_document
def _postCopy(self, container, op=0):
super(Base, self)._postCopy(container, op=op)
if op == 0: # copy (not cut)
# We are the copy of another document (either cloned or copy/pasted),
# forget id generator state.
try:
del self._id_generator_state
except AttributeError:
pass
security.declareProtected(Permissions.ModifyPortalContent, 'generateIdList')
def generateIdList(self, group, count=1, default=1, onMissing=None, poison=False):
"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment