Commit ba7da5a5 authored by Julien Muchembled's avatar Julien Muchembled

Link composed documents to the actual list of all initial specialise values

Given an order (-> TC1) with a line (-> TC2 -> TC3), line.asComposedDocument()
considers specialise values of the line and its parents, resulting in the union
of TC1', TC2' and TC3' (TC' being effective model of TC).
However, on a simulation movement linked to the line, we'd like to have
specialise_list = [TC2, TC1]. Now, this can be easily computed with:
  line.asComposedDocument().getSpecialiseList()

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37779 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 23575492
...@@ -120,12 +120,13 @@ class asComposedDocument(object): ...@@ -120,12 +120,13 @@ class asComposedDocument(object):
self.__class__ = type(base_class.__name__, (cls, base_class, BusinessProcess), {}) self.__class__ = type(base_class.__name__, (cls, base_class, BusinessProcess), {})
# here we could inherit many "useful" classes dynamically - héhé # here we could inherit many "useful" classes dynamically - héhé
# that would be a "real" abstract composition system # that would be a "real" abstract composition system
self._effective_model_list = \ self._effective_model_list, specialise_value_list = \
orig_self._findEffectiveSpecialiseValueList(specialise_type_list=portal_type_list) orig_self._findEffectiveAndInitialModelList(portal_type_list)
self._setValueList('specialise', specialise_value_list)
return self return self
def __init__(self, orig_self, portal_type_list=None): def __init__(self, orig_self, portal_type_list=None):
# __new__ does not call __init__ because returned object # __init__ is not called automatically after __new__ because returned object
# is wrapped in an acquisition context. # is wrapped in an acquisition context.
assert False assert False
...@@ -181,29 +182,35 @@ class CompositionMixin: ...@@ -181,29 +182,35 @@ class CompositionMixin:
This algorithm uses Breadth First Search. This algorithm uses Breadth First Search.
""" """
return self._findEffectiveAndInitialModelList(specialise_type_list)[0]
def _findEffectiveAndInitialModelList(self, specialise_type_list):
start_date = self.getStartDate() start_date = self.getStartDate()
stop_date = self.getStopDate() stop_date = self.getStopDate()
def getEffectiveModel(model): effective_list = [self]
return _getEffectiveModel(model, start_date, stop_date) effective_set = set()
model_list = [self] effective_index = 0
model_set = set(model_list) while effective_index < len(effective_list):
model_index = 0
while model_index < len(model_list):
model = model_list[model_index]
model_index += 1
# we don't use getSpecialiseValueList to avoid acquisition on the parent # we don't use getSpecialiseValueList to avoid acquisition on the parent
for model in map(getEffectiveModel, model.getValueList('specialise', model_list = effective_list[effective_index].getValueList('specialise',
portal_type=specialise_type_list or ())): portal_type=specialise_type_list or ())
if model not in model_set: if effective_set:
model_set.add(model) effective_index += 1
else: # first iteration
del effective_list[0]
specialise_value_list = model_list
for model in model_list:
model = _getEffectiveModel(model, start_date, stop_date)
if model not in effective_set:
effective_set.add(model)
if 1: #model.test(self): # XXX if 1: #model.test(self): # XXX
model_list.append(model) effective_list.append(model)
del model_list[0]
parent = self.getParentValue() parent = self.getParentValue()
if hasattr(aq_base(parent), 'asComposedDocument'): if hasattr(aq_base(parent), 'asComposedDocument'):
model_list += [model for model in parent.asComposedDocument( parent = parent.asComposedDocument(specialise_type_list)
specialise_type_list)._effective_model_list specialise_value_list += parent.getValueList('specialise')
if model not in model_set] effective_list += [model for model in parent._effective_model_list
return model_list if model not in effective_set]
return effective_list, specialise_value_list
del asComposedDocument # to be unhidden (and renamed ?) if needed del asComposedDocument # to be unhidden (and renamed ?) if needed
...@@ -2813,7 +2813,8 @@ class Base( CopyContainer, ...@@ -2813,7 +2813,8 @@ class Base( CopyContainer,
context.__dict__.update(kw) context.__dict__.update(kw)
# Make it a temp content # Make it a temp content
temp_object = TempBase(self.getId()) temp_object = TempBase(self.getId())
for k in ('isIndexable', 'reindexObject', 'recursiveReindexObject', 'activate', 'setUid', ): for k in ('isIndexable', 'isTempDocument', 'reindexObject',
'recursiveReindexObject', 'activate', 'setUid'):
setattr(context, k, getattr(temp_object, k)) setattr(context, k, getattr(temp_object, k))
# Return result # Return result
return context.__of__(self.aq_parent) return context.__of__(self.aq_parent)
......
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