Commit b9d9e7bf authored by Sebastien Robin's avatar Sebastien Robin

make sure that expand will expand all applied rules related to all movements of the delivery


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@6201 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent cf7446c1
...@@ -265,7 +265,6 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -265,7 +265,6 @@ class Delivery(XMLObject, ImmobilisationDelivery):
Returns 1 if all movements have a delivery or order counterpart Returns 1 if all movements have a delivery or order counterpart
in the simulation in the simulation
""" """
#LOG('Delivery.isSimulated getMovementList',0,self.getMovementList())
for m in self.getMovementList(): for m in self.getMovementList():
#LOG('Delivery.isSimulated m',0,m.getPhysicalPath()) #LOG('Delivery.isSimulated m',0,m.getPhysicalPath())
#LOG('Delivery.isSimulated m.isSimulated',0,m.isSimulated()) #LOG('Delivery.isSimulated m.isSimulated',0,m.isSimulated())
...@@ -276,7 +275,7 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -276,7 +275,7 @@ class Delivery(XMLObject, ImmobilisationDelivery):
return 0 return 0
# else Do we need to create a simulation movement ? XXX probably not # else Do we need to create a simulation movement ? XXX probably not
return 1 return 1
security.declareProtected(Permissions.View, 'isDivergent') security.declareProtected(Permissions.View, 'isDivergent')
def isDivergent(self,fast=0,**kw): def isDivergent(self,fast=0,**kw):
""" """
...@@ -557,6 +556,8 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -557,6 +556,8 @@ class Delivery(XMLObject, ImmobilisationDelivery):
# Nothing to do if we are already simulated # Nothing to do if we are already simulated
self._createAppliedRule(rule_id,force=force,**kw) self._createAppliedRule(rule_id,force=force,**kw)
def _createAppliedRule(self, rule_id,force=0,activate_kw=None,**kw): def _createAppliedRule(self, rule_id,force=0,activate_kw=None,**kw):
""" """
Create a new Applied Rule is none is related, or call expand Create a new Applied Rule is none is related, or call expand
...@@ -571,21 +572,23 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -571,21 +572,23 @@ class Delivery(XMLObject, ImmobilisationDelivery):
# Look up if existing applied rule # Look up if existing applied rule
my_applied_rule_list = self.getCausalityRelatedValueList(\ my_applied_rule_list = self.getCausalityRelatedValueList(\
portal_type='Applied Rule') portal_type='Applied Rule')
my_applied_rule = None
if len(my_applied_rule_list) == 0: if len(my_applied_rule_list) == 0:
if self.isSimulated(): if self.isSimulated():
# No need to create a DeliveryRule # No need to create a DeliveryRule
# if we are already in the simulation process # if we are already in the simulation process
return pass
# Create a new applied order rule (portal_rules.order_rule) else:
portal_rules = getToolByName(self, 'portal_rules') # Create a new applied order rule (portal_rules.order_rule)
portal_simulation = getToolByName(self, 'portal_simulation') portal_rules = getToolByName(self, 'portal_rules')
my_applied_rule = portal_rules[rule_id].\ portal_simulation = getToolByName(self, 'portal_simulation')
constructNewAppliedRule(portal_simulation) my_applied_rule = portal_rules[rule_id].\
# Set causality constructNewAppliedRule(portal_simulation)
my_applied_rule.setCausalityValue(self) # Set causality
# We must make sure this rule is indexed my_applied_rule.setCausalityValue(self)
# now in order not to create another one later # We must make sure this rule is indexed
my_applied_rule.reindexObject(activate_kw=activate_kw,**kw) # now in order not to create another one later
my_applied_rule.reindexObject(activate_kw=activate_kw,**kw)
elif len(my_applied_rule_list) == 1: elif len(my_applied_rule_list) == 1:
# Re expand the rule if possible # Re expand the rule if possible
my_applied_rule = my_applied_rule_list[0] my_applied_rule = my_applied_rule_list[0]
...@@ -593,32 +596,77 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -593,32 +596,77 @@ class Delivery(XMLObject, ImmobilisationDelivery):
raise "SimulationError", 'Delivery %s has more than one applied'\ raise "SimulationError", 'Delivery %s has more than one applied'\
' rule.' % self.getRelativeUrl() ' rule.' % self.getRelativeUrl()
my_applied_rule_id = None
expand_activate_kw = {}
if my_applied_rule is not None:
my_applied_rule_id = my_applied_rule.getId()
expand_activate_kw['after_path_and_method_id'] = \
(my_applied_rule.getPath(),\
['immediateReindexObject', 'recursiveImmediateReindexObject'])
# We are now certain we have a single applied rule # We are now certain we have a single applied rule
# It is time to expand it # It is time to expand it
self.activate( self.activate( activate_kw=activate_kw,
after_path_and_method_id=( **expand_activate_kw
my_applied_rule.getPath(), ).expand(applied_rule_id=my_applied_rule_id,force=force,
['immediateReindexObject', 'recursiveImmediateReindexObject']), activate_kw=activate_kw,**kw)
activate_kw=activate_kw
).expand(my_applied_rule.getId(),force=force,activate_kw=activate_kw,**kw)
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule_id, force=0, activate_kw=None,**kw): def expand(self, applied_rule_id=None, force=0, activate_kw=None,**kw):
""" """
Reexpand applied rule Reexpand applied rule
"""
my_applied_rule = self.portal_simulation.get(applied_rule_id, None) Also reexpand all rules related to movements
if my_applied_rule is not None: """
my_applied_rule.expand(force=force, activate_kw=activate_kw,**kw) excluded_rule_path_list = []
# once expanded, the applied_rule must be reindexed if applied_rule_id is not None:
# because some simulation_movement may change even my_applied_rule = self.portal_simulation.get(applied_rule_id, None)
# if there are not edited (acquisition) if my_applied_rule is not None:
my_applied_rule.recursiveReindexObject(activate_kw=activate_kw) excluded_rule_path_list.append(my_applied_rule.getPath())
else: my_applied_rule.expand(force=force, activate_kw=activate_kw,**kw)
LOG("ERP5 Error:", 100, # once expanded, the applied_rule must be reindexed
"Could not expand applied rule %s for delivery %s" %\ # because some simulation_movement may change even
(applied_rule_id, self.getId())) # if there are not edited (acquisition)
my_applied_rule.recursiveReindexObject(activate_kw=activate_kw)
else:
LOG("ERP5 Error:", 100,
"Could not expand applied rule %s for delivery %s" %\
(applied_rule_id, self.getId()))
self.expandRuleRelatedToMovement(
excluded_rule_path_list=excluded_rule_path_list,
force=force,
activate_kw=activate_kw,
**kw)
security.declareProtected(Permissions.ModifyPortalContent,
'expandRuleRelatedToMovement')
def expandRuleRelatedToMovement(self,excluded_rule_path_list=None,
activate_kw=None,**kw):
"""
Some delivery movement may be related to another applied rule than
the one related to the delivery. Delivery movements may be related
to many simulation movements from many different root applied rules,
so it is required to expand the applied rule parent to related
simulation movements.
exclude_rule_path : do not expand this applied rule (or children
applied rule)
"""
if excluded_rule_path_list is None:
excluded_rule_path_list = []
to_expand_list = []
# we might use a zsql method, because it can be very slow
for m in self.getMovementList():
if m.isSimulated():
sim_movement_list = m.getDeliveryRelatedValueList()
for sim_movement in sim_movement_list:
if sim_movement.getRootAppliedRule().getPath() \
not in excluded_rule_path_list:
parent_value = sim_movement.getParentValue()
if parent_value not in to_expand_list:
to_expand_list.append(parent_value)
for rule in to_expand_list:
rule.expand(activate_kw=activate_kw,**kw)
rule.recursiveReindexObject(activate_kw=activate_kw)
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getRootCausalityValueList') 'getRootCausalityValueList')
......
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