Commit a3d57401 authored by Alexandre Boeglin's avatar Alexandre Boeglin

* updateAppliedRule rule_id parameter renamed to rule_reference, as this is

    what the method now expects
* fix coding style (whitespace after comma)


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17555 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ce2310fb
...@@ -654,36 +654,36 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -654,36 +654,36 @@ class Delivery(XMLObject, ImmobilisationDelivery):
########################################################################## ##########################################################################
# Applied Rule stuff # Applied Rule stuff
def updateAppliedRule(self, rule_id,force=0,**kw): def updateAppliedRule(self, rule_reference, force=0, **kw):
""" """
Create a new Applied Rule if none is related, or call expand Create a new Applied Rule if none is related, or call expand
on the existing one. on the existing one.
The chosen applied rule will be the validated rule with reference == The chosen applied rule will be the validated rule with reference ==
rule_id, and the higher version number. rule_reference, and the higher version number.
If no rule is found, simply pass rule_id to _createAppliedRule, as we If no rule is found, simply pass rule_reference to _createAppliedRule,
did previously. to keep compatibility vith the previous behaviour
""" """
if rule_id is None: if rule_reference is None:
return return
portal_rules = getToolByName(self, 'portal_rules') portal_rules = getToolByName(self, 'portal_rules')
res = portal_rules.searchFolder(reference=rule_id, res = portal_rules.searchFolder(reference=rule_reference,
validation_state="validated", sort_on='version', validation_state="validated", sort_on='version',
sort_order='descending') # XXX validated is Hardcoded ! sort_order='descending') # XXX validated is Hardcoded !
if len(res) > 0: if len(res) > 0:
rule_id = res[0].getId() rule_id = res[0].getId()
else:
rule_id = rule_reference
if (self.getSimulationState() not in \ if (self.getSimulationState() not in
self.getPortalDraftOrderStateList()): self.getPortalDraftOrderStateList()):
# 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
on the existing one. on the existing one.
...@@ -695,8 +695,8 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -695,8 +695,8 @@ class Delivery(XMLObject, ImmobilisationDelivery):
return return
# Otherwise, expand # Otherwise, expand
# 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 my_applied_rule = None
if len(my_applied_rule_list) == 0: if len(my_applied_rule_list) == 0:
if self.isSimulated(): if self.isSimulated():
...@@ -708,32 +708,31 @@ class Delivery(XMLObject, ImmobilisationDelivery): ...@@ -708,32 +708,31 @@ class Delivery(XMLObject, ImmobilisationDelivery):
portal_rules = getToolByName(self, 'portal_rules') portal_rules = getToolByName(self, 'portal_rules')
portal_simulation = getToolByName(self, 'portal_simulation') portal_simulation = getToolByName(self, 'portal_simulation')
my_applied_rule = portal_rules[rule_id].\ my_applied_rule = portal_rules[rule_id].\
constructNewAppliedRule(portal_simulation) constructNewAppliedRule(portal_simulation)
# Set causality # Set causality
my_applied_rule.setCausalityValue(self) my_applied_rule.setCausalityValue(self)
# We must make sure this rule is indexed # We must make sure this rule is indexed
# now in order not to create another one later # now in order not to create another one later
my_applied_rule.reindexObject(activate_kw=activate_kw,**kw) 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]
else: else:
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 my_applied_rule_id = None
expand_activate_kw = {} expand_activate_kw = {}
if my_applied_rule is not None: if my_applied_rule is not None:
my_applied_rule_id = my_applied_rule.getId() my_applied_rule_id = my_applied_rule.getId()
expand_activate_kw['after_path_and_method_id'] = \ expand_activate_kw['after_path_and_method_id'] = (
(my_applied_rule.getPath(),\ my_applied_rule.getPath(),
['immediateReindexObject', 'recursiveImmediateReindexObject']) ['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( activate_kw=activate_kw, self.activate(activate_kw=activate_kw, **expand_activate_kw).expand(
**expand_activate_kw applied_rule_id=my_applied_rule_id, force=force,
).expand(applied_rule_id=my_applied_rule_id,force=force, activate_kw=activate_kw, **kw)
activate_kw=activate_kw,**kw)
security.declareProtected(Permissions.ModifyPortalContent, 'expand') security.declareProtected(Permissions.ModifyPortalContent, 'expand')
def expand(self, applied_rule_id=None, force=0, activate_kw=None,**kw): def expand(self, applied_rule_id=None, force=0, activate_kw=None,**kw):
......
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