Commit add8d9dc by Leonardo Rochael Almeida Committed by Julien Muchembled

Refactor AcceptSolver and AdoptSolver

1 parent e1a07bc5
......@@ -27,37 +27,16 @@
#
##############################################################################
import zope.interface
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
from Products.ERP5.mixin.solver import ConfigurablePropertySolverMixin
class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject):
class AcceptSolver(ConfigurablePropertySolverMixin):
"""Target solver that accepts the values from the decision on the prevision.
"""
meta_type = 'ERP5 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
# XXX-Leo: Needs security declaration! It's currently public.
def solve(self, activate_kw=None):
"""
Adopt new property to simulation movements, with keeping the
......@@ -90,11 +69,18 @@ class AcceptSolver(SolverMixin, ConfigurableMixin, XMLObject):
if solved_property == 'quantity':
new_value *= simulation_movement.getDeliveryRatio()
value_dict[solved_property] = new_value
self._updateSimulationMovement(simulation_movement, value_dict,
activate_kw)
# Finish solving
if portal.portal_workflow.isTransitionPossible(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)
# Finish solving
if portal.portal_workflow.isTransitionPossible(self, 'succeed'):
self.succeed()
......@@ -27,47 +27,21 @@
#
##############################################################################
import zope.interface
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
from Products.ERP5.mixin.solver import ConfigurablePropertySolverMixin
class AdoptSolver(SolverMixin, ConfigurableMixin, XMLObject):
class AdoptSolver(ConfigurablePropertySolverMixin):
"""Target solver that adopts the values from the prevision on the decision.
"""
meta_type = 'ERP5 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
# XXX-Leo: Needs security declaration! It's currently public.
def solve(self, activate_kw=None):
"""
Adopt new property to movements or deliveries.
"""
configuration_dict = self.getConfigurationPropertyDict()
portal_type = self.getPortalObject().portal_types.getTypeInfo(self)
solved_property_list = configuration_dict.get('tested_property_list',
portal_type.getTestedPropertyList())
solved_property_list = self.getTestedPropertyList()
delivery_dict = {}
for simulation_movement in self.getDeliveryValueList():
delivery_dict.setdefault(simulation_movement.getDeliveryValue(),
......
......@@ -29,9 +29,11 @@
import zope.interface
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.
"""
......@@ -58,3 +60,38 @@ class SolverMixin:
target_solver_type = self.getPortalTypeValue()
solver_list = target_solver_type.getDeliverySolverValueList()
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
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!