Commit 3f29602a authored by Julien Muchembled's avatar Julien Muchembled

builder: ignore property updates by movement groups if no document can be updated

This fixes how the builder processes the result of IMovementGroup.test.
Testing deliveries to find one that can be updated should have no impact
on properties if the builder ends up creating a delivery.
parent c5453025
...@@ -42,11 +42,8 @@ class OrderMovementGroup(MovementGroup): ...@@ -42,11 +42,8 @@ class OrderMovementGroup(MovementGroup):
return {'causality_list': [self._getOrderRelativeUrl(movement)]} return {'causality_list': [self._getOrderRelativeUrl(movement)]}
def test(self, movement, property_dict, **kw): def test(self, movement, property_dict, **kw):
if set(property_dict['causality_list']).issubset(movement.getCausalityList()): return set(property_dict['causality_list']
property_dict['causality_list'] = movement.getCausalityList() ).issubset(movement.getCausalityList()), {}
return True, property_dict
else:
return False, property_dict
def _getOrderRelativeUrl(self, movement): def _getOrderRelativeUrl(self, movement):
try: try:
......
...@@ -37,9 +37,17 @@ class IMovementGroup(Interface): ...@@ -37,9 +37,17 @@ class IMovementGroup(Interface):
""" """
def test(document, property_dict, **kw): def test(document, property_dict, **kw):
"""Returns a tuple of 2 values. """Returns a tuple of 2 values.
First one is True if document contains identical values than some First one is True if processed movements can be built to 'document'.
contained property_dict. Second one is a dict of properties that are set to 'document' if the
Second one is a modified version of property_dict. latter is actually chosen: it can be 'property_dict', which was the dict
returned by 'separate' for the considered movements.
'property_dict' shall be treated as immutable recursively. A modified
copy (deeply if necessary) can be returned.
A common implementation is to return a 2-tuple whose first value
is True when properties of 'document' are same as 'property_dict',
then there's usually no property to set and the second value is {}.
TODO: TODO:
- take into account the possibility to use Divergence Testers - take into account the possibility to use Divergence Testers
......
...@@ -323,18 +323,6 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -323,18 +323,6 @@ class BuilderMixin(XMLObject, Amount, Predicate):
root_group_node.append(movement_list) root_group_node.append(movement_list)
return root_group_node return root_group_node
def _test(self, instance, movement_group_node_list,
divergence_list):
result = True
new_property_dict_list = []
for movement_group_node in movement_group_node_list:
tmp_result, tmp_property_dict = movement_group_node.test(
instance, divergence_list)
if not tmp_result:
result = tmp_result
new_property_dict_list.append(tmp_property_dict)
return result, new_property_dict_list
@staticmethod @staticmethod
def _getSortedPropertyDict(property_dict_list): def _getSortedPropertyDict(property_dict_list):
# Sort the edit keywords according to the order of their movement # Sort the edit keywords according to the order of their movement
...@@ -357,7 +345,6 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -357,7 +345,6 @@ class BuilderMixin(XMLObject, Amount, Predicate):
def _findUpdatableObject(self, instance_list, movement_group_node_list, def _findUpdatableObject(self, instance_list, movement_group_node_list,
divergence_list): divergence_list):
instance = None
if instance_list: if instance_list:
# we want to check the original delivery first. # we want to check the original delivery first.
# so sort instance_list by that current is exists or not. # so sort instance_list by that current is exists or not.
...@@ -371,16 +358,19 @@ class BuilderMixin(XMLObject, Amount, Predicate): ...@@ -371,16 +358,19 @@ class BuilderMixin(XMLObject, Amount, Predicate):
current = current.getParentValue() current = current.getParentValue()
except AttributeError: except AttributeError:
pass pass
for instance_to_update in instance_list: for instance in instance_list:
result, property_dict_list = self._test( property_dict_list = []
instance_to_update, movement_group_node_list, divergence_list) for movement_group_node in movement_group_node_list:
if result: result, property_dict = movement_group_node.test(
instance = instance_to_update instance, divergence_list)
if not result:
break break
property_dict_list.append(property_dict)
else: else:
property_dict_list = [movement_group_node.getGroupEditDict()
for movement_group_node in movement_group_node_list]
return instance, self._getSortedPropertyDict(property_dict_list) return instance, self._getSortedPropertyDict(property_dict_list)
return None, self._getSortedPropertyDict(
movement_group_node.getGroupEditDict()
for movement_group_node in movement_group_node_list)
security.declarePrivate('buildDeliveryList') security.declarePrivate('buildDeliveryList')
@UnrestrictedMethod @UnrestrictedMethod
......
...@@ -164,8 +164,15 @@ class MovementGroupNode: ...@@ -164,8 +164,15 @@ class MovementGroupNode:
if not property_list: if not property_list:
return True, {} return True, {}
# else update anyway (eg. CausalityAssignmentMovementGroup etc.) # else update anyway (eg. CausalityAssignmentMovementGroup etc.)
return self._movement_group.test(movement, self._property_dict, result, property_dict = self._movement_group.test(
property_list=property_list) movement, self._property_dict, property_list=property_list)
# The following check is partial because it does not check mutable values
# recursively.
if property_dict is self._property_dict != property_dict:
raise ValueError(
"Movement Group must not modify the passed 'property_dict':"
" copy it, deeply if necessary, before editing properties")
return result, property_dict
else: else:
return True, {} return True, {}
......
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