Commit e24c1a44 authored by Aurel's avatar Aurel

browse the ZODB instead of using the catalog as some time simulation

movements are not yet commited

detect infinite loop - done by JPS



git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37409 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 421a8b82
...@@ -34,6 +34,9 @@ from Products.ERP5Type.TransactionalVariable import getTransactionalVariable ...@@ -34,6 +34,9 @@ from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from zLOG import LOG from zLOG import LOG
_UNDEFINED = []
_INFINITE_LOOP = []
class ExplanationCache: class ExplanationCache:
"""ExplanationCache provides a central access to """ExplanationCache provides a central access to
all parameters and values which are needed to process all parameters and values which are needed to process
...@@ -170,14 +173,37 @@ class ExplanationCache: ...@@ -170,14 +173,37 @@ class ExplanationCache:
browse parent and child movement browse parent and child movement
""" """
kw_tuple = tuple(kw.items()) # We hope that no sorting is needed kw_tuple = tuple(kw.items()) # We hope that no sorting is needed
if kw.get('path', None) is None:
kw['path'] = self.getSimulationPathPatternList() # XXX-JPS Explicit Query is better def getParentSimulationMovementValueList(obj, movement_list):
if kw.get('explanation_uid', None) is None: if getattr(obj, "getParentValue", None):
kw['explanation_uid'] = self.getRootExplanationUidList() parent = obj.getParentValue()
if parent is not None:
if parent.getPortalType() == "Simulation Movement":
movement_list.append(parent)
getParentSimulationMovementValueList(parent, movement_list)
def getChildSimulationMovementValueList(obj, movement_list):
child_list = obj.objectValues()
for child in child_list:
if child.getPortalType() == "Simulation Movement":
movement_list.append(child)
getChildSimulationMovementValueList(child, movement_list)
if self.simulation_movement_cache.get(kw_tuple, None) is None: if self.simulation_movement_cache.get(kw_tuple, None) is None:
self.simulation_movement_cache[kw_tuple] = \ if self.explanation.getPortalType() == "Applied Rule":
self.portal_catalog(portal_type="Simulation Movement", movement_list = []
**kw) getParentSimulationMovementValueList(self.explanation, movement_list)
getChildSimulationMovementValueList(self.explanation, movement_list)
self.simulation_movement_cache[kw_tuple] = movement_list
else:
if kw.get('path', None) is None:
kw['path'] = self.getSimulationPathPatternList() # XXX-JPS Explicit Query is better
if kw.get('explanation_uid', None) is None:
kw['explanation_uid'] = self.getRootExplanationUidList()
self.simulation_movement_cache[kw_tuple] = \
self.portal_catalog(portal_type="Simulation Movement",
**kw)
return self.simulation_movement_cache[kw_tuple] return self.simulation_movement_cache[kw_tuple]
def getBusinessLinkValueList(self, **kw): def getBusinessLinkValueList(self, **kw):
...@@ -275,6 +301,17 @@ class ExplanationCache: ...@@ -275,6 +301,17 @@ class ExplanationCache:
"""Browse parent similation movements until a movement with """Browse parent similation movements until a movement with
appropriate trade_phase is found. appropriate trade_phase is found.
""" """
tv = getTransactionalVariable(self)
reference_date_key = (trade_phase, reference_date_method_id, delay_mode, business_process.getPhysicalPath())
reference_date_key = repr(reference_date_key)
if tv.get(reference_date_key, _UNDEFINED) is _UNDEFINED:
tv[reference_date_key] = _INFINITE_LOOP
else:
result = tv[reference_date_key]
if result is _INFINITE_LOOP:
raise ValueError('No reference date is defined, probably due to missing Trade Model Path in Business Process')
return result
# Find simulation movements with appropriate trade_phase # Find simulation movements with appropriate trade_phase
movement_list = self.getSimulationMovementValueList(trade_phase=trade_phase) movement_list = self.getSimulationMovementValueList(trade_phase=trade_phase)
...@@ -284,7 +321,8 @@ class ExplanationCache: ...@@ -284,7 +321,8 @@ class ExplanationCache:
# but we should in reality some way to configure this # but we should in reality some way to configure this
movement = movement_list[0] movement = movement_list[0]
method = getattr(movement, reference_date_method_id) method = getattr(movement, reference_date_method_id)
return method() result = tv[reference_date_key] = method()
return result
# Case 2: we must recursively find another trade phase # Case 2: we must recursively find another trade phase
# to find the value recursively # to find the value recursively
...@@ -307,7 +345,8 @@ class ExplanationCache: ...@@ -307,7 +345,8 @@ class ExplanationCache:
start_date=start_date, stop_date=stop_date, start_date=start_date, stop_date=stop_date,
trade_phase=trade_phase, causality=path) trade_phase=trade_phase, causality=path)
method = getattr(movement, reference_date_method_id) method = getattr(movement, reference_date_method_id)
return method() result = tv[reference_date_key] = method()
return result
def _getExplanationCache(explanation): def _getExplanationCache(explanation):
# Return cached value if any # Return cached value if any
......
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