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())
...@@ -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,11 +572,13 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -571,11 +572,13 @@ 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
else:
# Create a new applied order rule (portal_rules.order_rule) # Create a new applied order rule (portal_rules.order_rule)
portal_rules = getToolByName(self, 'portal_rules') portal_rules = getToolByName(self, 'portal_rules')
portal_simulation = getToolByName(self, 'portal_simulation') portal_simulation = getToolByName(self, 'portal_simulation')
...@@ -593,22 +596,32 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -593,22 +596,32 @@ 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
Also reexpand all rules related to movements
""" """
excluded_rule_path_list = []
if applied_rule_id is not None:
my_applied_rule = self.portal_simulation.get(applied_rule_id, None) my_applied_rule = self.portal_simulation.get(applied_rule_id, None)
if my_applied_rule is not None: if my_applied_rule is not None:
excluded_rule_path_list.append(my_applied_rule.getPath())
my_applied_rule.expand(force=force, activate_kw=activate_kw,**kw) my_applied_rule.expand(force=force, activate_kw=activate_kw,**kw)
# once expanded, the applied_rule must be reindexed # once expanded, the applied_rule must be reindexed
# because some simulation_movement may change even # because some simulation_movement may change even
...@@ -618,7 +631,42 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -618,7 +631,42 @@ class Delivery(XMLObject, ImmobilisationDelivery):
LOG("ERP5 Error:", 100, LOG("ERP5 Error:", 100,
"Could not expand applied rule %s for delivery %s" %\ "Could not expand applied rule %s for delivery %s" %\
(applied_rule_id, self.getId())) (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