Commit ccadeaa4 authored by Jérome Perrin's avatar Jérome Perrin

Revert "simulation: introduce Rule.getSimulationMovementSimulationState"

This reverts commit 5e21f77f.

This was done too quickly based on a wrong assumption that simulation
movements to build would always be in planned state and that we could
have an efficient way of selecting them by catalog with index on
portal_type and simulation state, but it does not work this way.

Maybe the change is useful for something else, but since we don't have
any use case for now, let's just revert.
parent 009dd3c7
......@@ -36,6 +36,8 @@ from Products.ERP5Type.Utils import ensure_list
from erp5.component.document.Movement import Movement
from erp5.component.module.ExpandPolicy import policy_dict, TREE_DELIVERED_CACHE_KEY
from zLOG import LOG, WARNING
from Products.ERP5.mixin.property_recordable import PropertyRecordableMixin
from erp5.component.mixin.ExplainableMixin import ExplainableMixin
from erp5.component.interface.IExpandable import IExpandable
......@@ -126,8 +128,13 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin):
def getSimulationState(self, id_only=1):
"""Returns the current state in simulation
Inherit from delivery when built, otherwise, let the rule decide.
Inherit from delivery or parent (using a conversion table to make orders
planned when parent is confirmed).
In the case of simulation coming from an item, the simulation state is
delegated to the item.
XXX: movements in zero stock rule can not acquire simulation state
"""
delivery = self.getDeliveryValue()
if delivery is not None:
......@@ -138,9 +145,18 @@ class SimulationMovement(PropertyRecordableMixin, Movement, ExplainableMixin):
return order.getSimulationState()
applied_rule = self.getParentValue()
rule = applied_rule.getSpecialiseValue()
if rule is not None:
return rule.getSimulationMovementSimulationState(self)
parent = applied_rule.getParentValue()
try:
if isinstance(parent, SimulationMovement):
return parent_to_movement_simulation_state[parent.getSimulationState()]
getState = applied_rule.getCausalityValue() \
.aq_explicit.getSimulationMovementSimulationState
except (AttributeError, KeyError):
LOG('SimulationMovement.getSimulationState', WARNING,
'Could not acquire simulation state from %s'
% self.getRelativeUrl(), error=True)
else:
return getState(self)
security.declareProtected( Permissions.AccessContentsInformation,
'getTranslatedSimulationStateTitle')
......
......@@ -73,8 +73,3 @@ class IRule(IMovementCollectionUpdater):
Available policies: immediate, deferred, vertical_time_bound
"""
def getSimulationMovementSimulationState(simulation_movement):
"""
Compute the simulation state of this simulation movement.
"""
......@@ -26,22 +26,16 @@
#
##############################################################################
import logging
import zope.interface
from AccessControl import ClassSecurityInfo
from Products.ERP5Type.Globals import InitializeClass
from Products.ERP5Type import Permissions
from Products.ERP5Type.Core.Predicate import Predicate
from erp5.component.module.ExpandPolicy import policy_dict
from erp5.component.document.SimulationMovement import SimulationMovement, parent_to_movement_simulation_state
from erp5.component.interface.IRule import IRule
from erp5.component.interface.IDivergenceController import IDivergenceController
from erp5.component.interface.IMovementCollectionUpdater import IMovementCollectionUpdater
logger = logging.getLogger(__name__)
def _compare(tester_list, prevision_movement, decision_movement):
for tester in tester_list:
if not tester.compare(prevision_movement, decision_movement):
......@@ -133,36 +127,6 @@ class RuleMixin(Predicate):
"""
return not movement.getDelivery()
security.declareProtected(Permissions.AccessContentsInformation,
'getSimulationMovementSimulationState')
def getSimulationMovementSimulationState(self, simulation_movement):
"""
Compute the simulation state of this simulation movement.
Inherit from parent movement, using a conversion table to make
orders planned when parent is confirmed.
In the case of simulation coming from an item, the simulation state is
delegated to the item.
This method can be overridden in custom rule class to generate movements
with a different simulation state.
"""
applied_rule = simulation_movement.getParentValue()
parent_simulation_movement = applied_rule.getParentValue()
try:
if isinstance(parent_simulation_movement, SimulationMovement):
return parent_to_movement_simulation_state[parent_simulation_movement.getSimulationState()]
getSimulationMovementSimulationState = applied_rule.getCausalityValue() \
.aq_explicit.getSimulationMovementSimulationState
except (AttributeError, KeyError):
logger.warning(
'getSimulationState: Could not acquire simulation state from %s',
simulation_movement,
exc_info=True)
else:
return getSimulationMovementSimulationState(simulation_movement)
# Implementation of IDivergenceController # XXX-JPS move to IDivergenceController only mixin for
security.declareProtected( Permissions.AccessContentsInformation,
'isDivergent')
......
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