Commit e63028b4 authored by Romain Courteaud's avatar Romain Courteaud

Causality is now tested by Divergence Tester.

Rules now need to include divergence testers.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@11285 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 825e0c2e
......@@ -284,7 +284,7 @@ class Delivery(XMLObject, ImmobilisationDelivery):
return 1
security.declareProtected(Permissions.View, 'isDivergent')
def isDivergent(self,fast=0,**kw):
def isDivergent(self, fast=0, **kw):
"""
Returns 1 if the target is not met according to the current information
After and edit, the isOutOfTarget will be checked. If it is 1,
......@@ -304,6 +304,16 @@ class Delivery(XMLObject, ImmobilisationDelivery):
return 1
return 0
security.declareProtected(Permissions.View, 'getDivergenceList')
def getDivergenceList(self):
"""
Return a list of messages that contains the divergences
"""
divergence_list = []
for movement in self.getMovementList():
divergence_list.extend(movement.getDivergenceList())
return divergence_list
def updateCausalityState(self,**kw):
"""
This is often called as an activity, it will check if the
......
......@@ -69,6 +69,7 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated,
, PropertySheet.Price
, PropertySheet.VariationRange
, PropertySheet.ItemAggregation
, PropertySheet.SortIndex
)
# Multiple inheritance definition
......@@ -217,12 +218,24 @@ class DeliveryLine(Movement, XMLObject, XMLMatrix, Variated,
emit targetUnreachable !
"""
if self.hasCellContent():
for cell in self.contentValues(filter={'portal_type': self.getPortalDeliveryMovementTypeList()}):
if cell.isDivergent():
if self.getDivergenceList() == []:
return 0
else:
return 1
security.declareProtected(Permissions.View, 'getDivergentList')
def getDivergenceList(self):
"""
Return a list of messages that contains the divergences
"""
divergence_list = []
if self.hasCellContent():
for cell in self.contentValues(filter={
'portal_type': self.getPortalDeliveryMovementTypeList()}):
divergence_list.extend(cell.getDivergenceList())
return divergence_list
else:
return Movement.isDivergent(self)
return Movement.getDivergenceList(self)
def applyToDeliveryLineRelatedMovement(self, portal_type='Simulation Movement', method_id = 'expand'):
# Find related in simulation
......
......@@ -89,9 +89,8 @@ class DeliveryRule(Rule):
delivery_movement_list = delivery.getMovementList()
# Check existing movements
for movement in applied_rule.contentValues(portal_type=movement_type):
if movement.getLastExpandSimulationState() not in \
delivery.getPortalCurrentInventoryStateList():
if movement.getLastExpandSimulationState() in \
delivery.getPortalDraftOrderStateList():
movement_delivery = movement.getDeliveryValue()
if not self._isTreeDelivered([movement], ignore_first=1) and \
movement_delivery not in delivery_movement_list:
......@@ -184,7 +183,7 @@ class DeliveryRule(Rule):
# Solvers
security.declareProtected(Permissions.AccessContentsInformation, 'isStable')
def isStable(self, movement):
def isStable(self, applied_rule):
"""
Checks that the applied_rule is stable
"""
......
......@@ -186,7 +186,6 @@ class InvoiceTransactionRule(Rule, PredicateMatrix):
# Pass to base class
Rule.expand(self, applied_rule, force=force, **kw)
# Matrix related
security.declareProtected( Permissions.ModifyPortalContent,
'newCellContent' )
......@@ -221,24 +220,24 @@ class InvoiceTransactionRule(Rule, PredicateMatrix):
and blocks expansion process
"""
# Solvers
security.declareProtected(Permissions.View, 'isDivergent')
def isDivergent(self, applied_rule):
"""
Returns 1 if divergent rule
"""
security.declareProtected(Permissions.View, 'getDivergenceList')
def getDivergenceList(self, applied_rule):
"""
Returns a list Divergence descriptors
"""
security.declareProtected(Permissions.View, 'getSolverList')
def getSolverList(self, applied_rule):
"""
Returns a list Divergence solvers
"""
# # Solvers
# security.declareProtected(Permissions.View, 'isDivergent')
# def isDivergent(self, applied_rule):
# """
# Returns 1 if divergent rule
# """
#
# security.declareProtected(Permissions.View, 'getDivergenceList')
# def getDivergenceList(self, applied_rule):
# """
# Returns a list Divergence descriptors
# """
#
# security.declareProtected(Permissions.View, 'getSolverList')
# def getSolverList(self, applied_rule):
# """
# Returns a list Divergence solvers
# """
# Deliverability / orderability
def isOrderable(self, m):
......
......@@ -38,7 +38,7 @@ from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Amount import Amount
from zLOG import LOG, WARNING
from zLOG import LOG, WARNING, DEBUG
class Movement(XMLObject, Amount):
"""
......@@ -423,6 +423,16 @@ class Movement(XMLObject, Amount):
return 1
return 0
def getDivergenceList(self):
"""
Return a list of messages that contains the divergences
"""
divergence_list = []
for simulation_movement in self.getDeliveryRelatedValueList():
divergence_list.extend(simulation_movement.getDivergenceList())
return divergence_list
security.declareProtected(Permissions.AccessContentsInformation,
'isFrozen')
def isFrozen(self):
......@@ -435,7 +445,7 @@ class Movement(XMLObject, Amount):
# XXX Hardcoded
# Maybe, we should use getPortalCurrentInventoryStateList
# and another portal method for cancelled (and deleted)
#LOG("Movement, isFrozen", WARNING, "Hardcoded state list")
# LOG("Movement, isFrozen", DEBUG, "Hardcoded state list")
if self.getSimulationState() in ('stopped', 'delivered', 'cancelled'):
return 1
if self._baseIsFrozen() == 0:
......
......@@ -175,53 +175,36 @@ class Rule(XMLObject, Predicate):
# Solvers
security.declareProtected( Permissions.AccessContentsInformation,
'isDivergent')
def isDivergent(self, movement, ignore_list=[]):
def isDivergent(self, sim_mvt, ignore_list=[]):
"""
Returns true if the Simulation Movement is divergent comparing to
the delivery value
"""
delivery = movement.getDeliveryValue()
delivery = sim_mvt.getDeliveryValue()
if delivery is None:
return 0
default_match_list = (
'source_section', 'destination_section', 'source',
'destination', 'resource', 'variation_category_list',
'aggregate_list', 'start_date', 'stop_date')
match_list = [x for x in default_match_list if x not in ignore_list]
for prop in match_list:
if movement.getProperty(prop) != delivery.getProperty(prop):
return 1
d_quantity = delivery.getQuantity()
quantity = movement.getCorrectedQuantity()
d_error = movement.getDeliveryError()
if quantity is None:
if d_quantity is None:
if self.getDivergenceList(sim_mvt) == []:
return 0
else:
return 1
if d_quantity is None:
d_quantity = 0
if d_error is None:
d_error = 0
delivery_ratio = movement.getDeliveryRatio()
# if the delivery_ratio is None, make sure that we are
# divergent even if the delivery quantity is 0
if delivery_ratio is not None:
d_quantity *= delivery_ratio
if delivery_ratio == 0 and quantity > 0:
return 1
if d_quantity != quantity + d_error:
return 1
return 0
# security.declareProtected(Permissions.View, 'getDivergenceList')
# def getDivergenceList(self, applied_rule):
# """
# Returns a list Divergence descriptors
# """
#
security.declareProtected(Permissions.View, 'getDivergenceList')
def getDivergenceList(self, sim_mvt):
"""
Return a list of messages that contains the divergences.
"""
result_list = []
for divergence_tester in self.contentValues(
portal_type=self.getPortalDivergenceTesterTypeList()):
result = divergence_tester.explain(sim_mvt)
result_list.extend(result)
return result_list
# XXX getSolverList is not part of the API and should be removed.
# Use getDivergenceList instead.
# security.declareProtected(Permissions.View, 'getSolverList')
# def getSolverList(self, applied_rule):
# """
# Returns a list Divergence solvers
......@@ -330,8 +313,8 @@ class Rule(XMLObject, Predicate):
p_matched_list.append(movement)
# XXX hardcoded ...
LOG("Rule, _getCompensatedMovementList", WARNING,
"Hardcoded properties check")
# LOG("Rule, _getCompensatedMovementList", WARNING,
# "Hardcoded properties check")
# Movements exist, we'll try to make them match the prevision
if p_matched_list != []:
# Check the quantity
......
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