Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Łukasz Nowak
erp5
Commits
add8d9dc
Commit
add8d9dc
authored
Aug 22, 2012
by
Leonardo Rochael Almeida
Committed by
Julien Muchembled
Jan 29, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor AcceptSolver and AdoptSolver
parent
e1a07bc5
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
61 deletions
+58
-61
product/ERP5/Document/AcceptSolver.py
product/ERP5/Document/AcceptSolver.py
+15
-29
product/ERP5/Document/AdoptSolver.py
product/ERP5/Document/AdoptSolver.py
+4
-30
product/ERP5/mixin/solver.py
product/ERP5/mixin/solver.py
+39
-2
No files found.
product/ERP5/Document/AcceptSolver.py
View file @
add8d9dc
...
...
@@ -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
()
product/ERP5/Document/AdoptSolver.py
View file @
add8d9dc
...
...
@@ -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
(),
...
...
product/ERP5/mixin/solver.py
View file @
add8d9dc
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment