Commit 263b6170 authored by Julien Muchembled's avatar Julien Muchembled

Fix misuse of getTransactionalVariable

getTransactionalVariable ignores given parameter.

git-svn-id: https://svn.erp5.org/repos/public/erp5/sandbox/amount_generator@37932 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c6ae952f
...@@ -28,14 +28,10 @@ ...@@ -28,14 +28,10 @@
############################################################################## ##############################################################################
import types import types
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
from zLOG import LOG from zLOG import LOG
from Products.CMFCore.utils import getToolByName
from Products.ERP5Type.Cache import transactional_cached
_UNDEFINED = []
_INFINITE_LOOP = []
class ExplanationCache: class ExplanationCache:
"""ExplanationCache provides a central access to """ExplanationCache provides a central access to
...@@ -60,6 +56,7 @@ class ExplanationCache: ...@@ -60,6 +56,7 @@ class ExplanationCache:
self.simulation_movement_cache = {} # Simulation Movement Cache self.simulation_movement_cache = {} # Simulation Movement Cache
self.explanation_uid_cache = [] self.explanation_uid_cache = []
self.explanation_path_pattern_cache = [] self.explanation_path_pattern_cache = []
self.reference_date_cache = {}
self.closure_cache = {} self.closure_cache = {}
self.union_cache = None self.union_cache = None
...@@ -311,21 +308,21 @@ class ExplanationCache: ...@@ -311,21 +308,21 @@ class ExplanationCache:
self.union_cache = new_business_process self.union_cache = new_business_process
return new_business_process return new_business_process
def getReferenceDate(self, business_process, trade_phase, reference_date_method_id, delay_mode=None): def getReferenceDate(self, business_process, trade_phase,
reference_date_method_id, delay_mode=None):
"""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) cache = self.reference_date_cache
reference_date_key = (trade_phase, reference_date_method_id, delay_mode, business_process.getPhysicalPath()) reference_date_key = (business_process.getPhysicalPath(), trade_phase,
reference_date_key = repr(reference_date_key) reference_date_method_id, delay_mode)
LOG('key', 0, reference_date_key) try:
if tv.get(reference_date_key, _UNDEFINED) is _UNDEFINED: result = cache[reference_date_key]
tv[reference_date_key] = _INFINITE_LOOP if result is self: # use self as marker to detect infinite recursion
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') raise ValueError('No reference date is defined, probably due to missing Trade Model Path in Business Process')
return result return result
except KeyError:
cache[reference_date_key] = self
# 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)
...@@ -336,7 +333,7 @@ class ExplanationCache: ...@@ -336,7 +333,7 @@ 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)
result = tv[reference_date_key] = method() cache[reference_date_key] = result = method()
return result return result
# Case 2: we must recursively find another trade phase # Case 2: we must recursively find another trade phase
...@@ -361,15 +358,10 @@ class ExplanationCache: ...@@ -361,15 +358,10 @@ 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)
result = tv[reference_date_key] = method() cache[reference_date_key] = result = method()
return result return result
def _getExplanationCache(explanation): _getExplanationCache = transactional_cached()(ExplanationCache)
# Return cached value if any
tv = getTransactionalVariable(explanation)
if tv.get('explanation_cache', None) is None:
tv['explanation_cache'] = ExplanationCache(explanation)
return tv.get('explanation_cache')
def _getBusinessLinkClosure(business_process, explanation, business_link): def _getBusinessLinkClosure(business_process, explanation, business_link):
"""Returns a closure Business Process for given """Returns a closure Business Process for given
......
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