Commit 8063c50a authored by Julien Muchembled's avatar Julien Muchembled

code simplification

parent aa3a313d
......@@ -348,11 +348,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
if old_delivery is None:
# from scratch
new_delivery_id = str(delivery_module.generateNewId())
delivery = delivery_module.newContent(
portal_type=self.getDeliveryPortalType(),
id=new_delivery_id,
created_by_builder=1,
activate_kw=activate_kw)
delivery = super(SimulatedDeliveryBuilder, self)._createDelivery(
delivery_module, movement_list, activate_kw)
else:
# from duplicated original delivery
cp = tryMethodCallWithTemporaryPermission(
......@@ -383,10 +380,8 @@ class SimulatedDeliveryBuilder(BuilderMixin):
old_delivery_line = None
if old_delivery_line is None:
# from scratch
new_delivery_line_id = str(delivery.generateNewId())
delivery_line = delivery.newContent(
portal_type=self.getDeliveryLinePortalType(),
id=new_delivery_line_id,
variation_category_list=[],
activate_kw=activate_kw)
else:
......
......@@ -164,7 +164,7 @@ class BuilderMixin(XMLObject, Amount, Predicate):
"""
delivery_module_before_building_script_id = \
self.getDeliveryModuleBeforeBuildingScriptId()
if delivery_module_before_building_script_id not in ["", None]:
if delivery_module_before_building_script_id:
delivery_module = getattr(self.getPortalObject(), self.getDeliveryModule())
getattr(delivery_module, delivery_module_before_building_script_id)()
......@@ -369,13 +369,10 @@ class BuilderMixin(XMLObject, Amount, Predicate):
Create a new delivery in case where a builder may not update
an existing one.
"""
new_delivery_id = str(delivery_module.generateNewId())
delivery = delivery_module.newContent(
return delivery_module.newContent(
portal_type=self.getDeliveryPortalType(),
id=new_delivery_id,
created_by_builder=1,
activate_kw=activate_kw)
return delivery
def _processDeliveryGroup(self, delivery_module, movement_group_node,
collect_order_list, movement_group_node_list=None,
......@@ -453,13 +450,10 @@ class BuilderMixin(XMLObject, Amount, Predicate):
Create a new delivery line in case where a builder may not update
an existing one.
"""
new_delivery_line_id = str(delivery.generateNewId())
delivery_line = delivery.newContent(
return delivery.newContent(
portal_type=self.getDeliveryLinePortalType(),
id=new_delivery_line_id,
created_by_builder=1,
activate_kw=activate_kw)
return delivery_line
def _processDeliveryLineGroup(self, delivery, movement_group_node,
collect_order_list, movement_group_node_list=None,
......@@ -686,42 +680,33 @@ class BuilderMixin(XMLObject, Amount, Predicate):
delivery_movement._edit(force_update=1, **property_dict)
@UnrestrictedMethod
def callAfterBuildingScript(self, delivery_list, movement_list=None, **kw):
def callAfterBuildingScript(self, delivery_list, movement_list=(), **kw):
"""
Call script on each delivery built.
"""
if not len(delivery_list):
return
# Parameter initialization
if movement_list is None:
movement_list = []
delivery_after_generation_script_id = \
self.getDeliveryAfterGenerationScriptId()
if delivery_after_generation_script_id:
related_simulation_movement_path_list = \
[x.getPath() for x in movement_list]
if delivery_after_generation_script_id not in ["", None]:
for delivery in delivery_list:
script = getattr(delivery, delivery_after_generation_script_id)
# BBB: Only Python Scripts were used in the past, and they might not
# accept an arbitrary argument. So to keep compatibility,
# check if it can take the new parameter safely, only when
# the callable object is a Python Script.
safe_to_pass_parameter = True
meta_type = getattr(script, 'meta_type', None)
if meta_type == 'Script (Python)':
# check if the script accepts related_simulation_movement_path_list
safe_to_pass_parameter = False
for param in script.params().split(','):
param = param.split('=', 1)[0].strip()
if param == 'related_simulation_movement_path_list' \
or param.startswith('**'):
safe_to_pass_parameter = True
break
if safe_to_pass_parameter:
script(related_simulation_movement_path_list=related_simulation_movement_path_list)
else:
script()
continue
script(related_simulation_movement_path_list=related_simulation_movement_path_list)
security.declareProtected(Permissions.AccessContentsInformation,
'getMovementGroupList')
......
......@@ -1436,22 +1436,23 @@ class Base( CopyContainer,
# We only change if the value is different
# This may be very long...
if force_update:
update = True
old_value = None
else:
try:
old_value = getProperty(key, evaluate=0)
except TypeError:
old_value = getProperty(key)
update = old_value != kw[key]
if old_value == kw[key]:
not_modified_list.append(key)
continue
if update:
# We keep in a thread var the previous values
# this can be useful for interaction workflow to implement lookups
# XXX If iteraction workflow script is triggered by edit and calls
# edit itself, this is useless as the dict will be overwritten
# If the keep_existing flag is set to 1, we do not update properties which are defined
if not keep_existing or not hasProperty(key):
if keep_existing and hasProperty(key):
continue
if restricted:
accessor_name = 'set' + UpperCase(key)
if accessor_name in restricted_method_set:
......@@ -1471,8 +1472,6 @@ class Base( CopyContainer,
modified_object_dict[id(o)] = o
else:
self.setId(kw['id'], reindex=reindex_object)
else:
not_modified_list.append(key)
return not_modified_list
unmodified_key_list = setChangedPropertyList(unordered_key_list)
......
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