Commit add8d9dc authored by Leonardo Rochael Almeida's avatar Leonardo Rochael Almeida Committed by Julien Muchembled

Refactor AcceptSolver and AdoptSolver

parent e1a07bc5
...@@ -27,37 +27,16 @@ ...@@ -27,37 +27,16 @@
# #
############################################################################## ##############################################################################
import zope.interface from Products.ERP5.mixin.solver import ConfigurablePropertySolverMixin
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.mixin.solver import SolverMixin
from Products.ERP5.mixin.configurable import ConfigurableMixin
class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject): class AcceptSolver(ConfigurablePropertySolverMixin):
"""Target solver that accepts the values from the decision on the prevision. """Target solver that accepts the values from the decision on the prevision.
""" """
meta_type = 'ERP5 Accept Solver' meta_type = 'ERP5 Accept Solver'
portal_type = 'Accept Solver' portal_type = 'Accept Solver'
add_permission = Permissions.AddPortalContent
isIndexable = 0 # We do not want to fill the catalog with objects on which we need no reporting
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.TargetSolver
)
# Declarative interfaces
zope.interface.implements(interfaces.ISolver,)
# ISolver Implementation # ISolver Implementation
# XXX-Leo: Needs security declaration! It's currently public.
def solve(self, activate_kw=None): def solve(self, activate_kw=None):
""" """
Adopt new property to simulation movements, with keeping the Adopt new property to simulation movements, with keeping the
...@@ -90,11 +69,18 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject): ...@@ -90,11 +69,18 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject):
if solved_property == 'quantity': if solved_property == 'quantity':
new_value *= simulation_movement.getDeliveryRatio() new_value *= simulation_movement.getDeliveryRatio()
value_dict[solved_property] = new_value value_dict[solved_property] = new_value
for property_id, value in value_dict.iteritems(): self._updateSimulationMovement(simulation_movement, value_dict,
if not simulation_movement.isPropertyRecorded(property_id): activate_kw)
simulation_movement.recordProperty(property_id)
simulation_movement.setMappedProperty(property_id, value)
simulation_movement.expand(activate_kw=activate_kw)
# Finish solving # Finish solving
if portal.portal_workflow.isTransitionPossible(self, 'succeed'): if portal.portal_workflow.isTransitionPossible(self, 'succeed'):
self.succeed() self.succeed()
# allow subclasses to override this method and do interesting things
# like recording the same values in other simulation movements
def _updateSimulationMovement(self, simulation_movement, value_dict,
activate_kw):
for property_id, value in value_dict.iteritems():
if not simulation_movement.isPropertyRecorded(property_id):
simulation_movement.recordProperty(property_id)
simulation_movement.setMappedProperty(property_id, value)
simulation_movement.expand(activate_kw=activate_kw)
...@@ -27,47 +27,21 @@ ...@@ -27,47 +27,21 @@
# #
############################################################################## ##############################################################################
import zope.interface from Products.ERP5.mixin.solver import ConfigurablePropertySolverMixin
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.mixin.solver import SolverMixin
from Products.ERP5.mixin.configurable import ConfigurableMixin
class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject): class AdoptSolver(ConfigurablePropertySolverMixin):
"""Target solver that adopts the values from the prevision on the decision. """Target solver that adopts the values from the prevision on the decision.
""" """
meta_type = 'ERP5 Adopt Solver' meta_type = 'ERP5 Adopt Solver'
portal_type = 'Adopt Solver' portal_type = 'Adopt Solver'
add_permission = Permissions.AddPortalContent
isIndexable = 0 # We do not want to fill the catalog with objects on which we need no reporting
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.TargetSolver
)
# Declarative interfaces
zope.interface.implements(interfaces.ISolver,
interfaces.IConfigurable,
)
# ISolver Implementation # ISolver Implementation
# XXX-Leo: Needs security declaration! It's currently public.
def solve(self, activate_kw=None): def solve(self, activate_kw=None):
""" """
Adopt new property to movements or deliveries. Adopt new property to movements or deliveries.
""" """
configuration_dict = self.getConfigurationPropertyDict() solved_property_list = self.getTestedPropertyList()
portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = configuration_dict.get('tested_property_list',
portal_type.getTestedPropertyList())
delivery_dict = {} delivery_dict = {}
for simulation_movement in self.getDeliveryValueList(): for simulation_movement in self.getDeliveryValueList():
delivery_dict.setdefault(simulation_movement.getDeliveryValue(), delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
......
...@@ -29,9 +29,11 @@ ...@@ -29,9 +29,11 @@
import zope.interface import zope.interface
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, interfaces from Products.ERP5Type import Permissions, PropertySheet, interfaces
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.mixin.configurable import ConfigurableMixin
class SolverMixin: class SolverMixin(object):
""" """
Provides generic methods and helper methods to implement ISolver. Provides generic methods and helper methods to implement ISolver.
""" """
...@@ -58,3 +60,38 @@ class SolverMixin: ...@@ -58,3 +60,38 @@ class SolverMixin:
target_solver_type = self.getPortalTypeValue() target_solver_type = self.getPortalTypeValue()
solver_list = target_solver_type.getDeliverySolverValueList() solver_list = target_solver_type.getDeliverySolverValueList()
return solver_list return solver_list
class ConfigurablePropertySolverMixin(SolverMixin,
ConfigurableMixin,
XMLObject):
"""
Base class for Target Solvers that can be applied to many
solver-decisions of a solver process, and need to accumulate the
tested_property_list configuration among all solver-decisions
"""
add_permission = Permissions.AddPortalContent
isIndexable = 0 # We do not want to fill the catalog with objects on which we need no reporting
# Declarative security
security = ClassSecurityInfo()
security.declareObjectProtected(Permissions.AccessContentsInformation)
zope.interface.implements(interfaces.ISolver,
interfaces.IConfigurable,)
# Default Properties
property_sheets = ( PropertySheet.Base
, PropertySheet.XMLObject
, PropertySheet.CategoryCore
, PropertySheet.DublinCore
, PropertySheet.TargetSolver
)
def getTestedPropertyList(self):
configuration_dict = self.getConfigurationPropertyDict()
tested_property_list = configuration_dict.get('tested_property_list')
if tested_property_list is None:
portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
tested_property_list = portal_type.getTestedPropertyList()
return tested_property_list
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