From 53af2b82fcc2104ef9854e0f403fbe94633cd354 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Wed, 17 Sep 2008 10:08:17 +0000
Subject: [PATCH] rename from testToUpdate() to test().

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23669 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BaseVariantMovementGroup.py   |  9 +--------
 product/ERP5/Document/CategoryMovementGroup.py      |  9 +++++----
 .../Document/CausalityAssignmentMovementGroup.py    |  2 +-
 product/ERP5/Document/CausalityMovementGroup.py     |  2 +-
 product/ERP5/Document/MovementGroup.py              | 13 ++++---------
 product/ERP5/Document/OrderBuilder.py               |  6 +++---
 product/ERP5/Document/OrderMovementGroup.py         |  2 +-
 .../ERP5/Document/ParentExplanationMovementGroup.py |  9 ++++++---
 product/ERP5/Document/PropertyMovementGroup.py      |  4 ++--
 product/ERP5/Document/QuantitySignMovementGroup.py  | 11 -----------
 product/ERP5/Document/RequirementMovementGroup.py   |  2 +-
 .../RootAppliedRuleCausalityMovementGroup.py        |  2 +-
 product/ERP5/Document/SplitMovementGroup.py         |  2 +-
 product/ERP5/Document/TitleMovementGroup.py         |  3 ---
 product/ERP5/Document/VariantMovementGroup.py       |  5 ++++-
 product/ERP5/MovementGroup.py                       |  4 ++--
 16 files changed, 33 insertions(+), 52 deletions(-)

diff --git a/product/ERP5/Document/BaseVariantMovementGroup.py b/product/ERP5/Document/BaseVariantMovementGroup.py
index 5475da335e..63cd720198 100644
--- a/product/ERP5/Document/BaseVariantMovementGroup.py
+++ b/product/ERP5/Document/BaseVariantMovementGroup.py
@@ -44,13 +44,6 @@ class BaseVariantMovementGroup(MovementGroup):
     property_dict['_base_category_list'] = category_list
     return property_dict
 
-  def test(self, object, property_dict):
-    category_list = object.getVariationBaseCategoryList()
-    if category_list is None:
-      category_list = []
-    category_list.sort()
-    return property_dict['_base_category_list'] == category_list
-
-  def testToUpdate(self, object, property_dict, **kw):
+  def test(self, object, property_dict, **kw):
     # This movement group does not affect updating.
     return True, {}
diff --git a/product/ERP5/Document/CategoryMovementGroup.py b/product/ERP5/Document/CategoryMovementGroup.py
index 44a64ea6c8..5427de8e64 100644
--- a/product/ERP5/Document/CategoryMovementGroup.py
+++ b/product/ERP5/Document/CategoryMovementGroup.py
@@ -41,7 +41,8 @@ class CategoryMovementGroup(PropertyMovementGroup):
   def _getPropertyDict(self, movement, **kw):
     property_dict = {}
     for prop in self.getTestedPropertyList():
-      property_dict['%s_list' % prop] = movement.getPropertyList(prop, None)
+      property_dict['%s_list' % prop] = sorted(
+        movement.getPropertyList(prop, None))
     return property_dict
 
   def test(self, object, property_dict, property_list=None, **kw):
@@ -51,7 +52,7 @@ class CategoryMovementGroup(PropertyMovementGroup):
     else:
       target_property_list = self.getTestedPropertyList()
     for prop in target_property_list:
-      if sorted(property_dict['%s_list' % prop]) != \
+      if property_dict['%s_list' % prop] != \
              sorted(object.getPropertyList(prop, None)):
-        return False
-    return True
+        return False, property_dict
+    return True, property_dict
diff --git a/product/ERP5/Document/CausalityAssignmentMovementGroup.py b/product/ERP5/Document/CausalityAssignmentMovementGroup.py
index 958c4dd31f..f36c6af94e 100644
--- a/product/ERP5/Document/CausalityAssignmentMovementGroup.py
+++ b/product/ERP5/Document/CausalityAssignmentMovementGroup.py
@@ -47,7 +47,7 @@ class CausalityAssignmentMovementGroup(MovementGroup):
       self._addCausalityToEdit(movement, property_dict)
     return [[movement_list, property_dict]]
 
-  def testToUpdate(self, movement, property_dict, **kw):
+  def test(self, movement, property_dict, **kw):
     # We can always update.
     return True, property_dict
 
diff --git a/product/ERP5/Document/CausalityMovementGroup.py b/product/ERP5/Document/CausalityMovementGroup.py
index 39d9600db5..884a96cd66 100644
--- a/product/ERP5/Document/CausalityMovementGroup.py
+++ b/product/ERP5/Document/CausalityMovementGroup.py
@@ -42,7 +42,7 @@ class CausalityMovementGroup(MovementGroup):
     property_dict['_explanation'] = explanation_relative_url
     return property_dict
 
-  def testToUpdate(self, movement, property_dict, **kw):
+  def test(self, movement, property_dict, **kw):
     # we don't care the difference of explanation url when updating
     #return True, property_dict
     return True, {}
diff --git a/product/ERP5/Document/MovementGroup.py b/product/ERP5/Document/MovementGroup.py
index a3a1836764..7369ef3d4a 100644
--- a/product/ERP5/Document/MovementGroup.py
+++ b/product/ERP5/Document/MovementGroup.py
@@ -54,6 +54,10 @@ class MovementGroup(XMLObject):
     # This method should be defined in sub classes.
     raise NotImplementedError
 
+  def test(self, object, property_dict, **kw):
+    # This method should be defined in sub classes.
+    raise NotImplementedError
+
   def _separate(self, movement_list):
     # By default, we separate movements by _getPropertyDict() values.
     # You can override this method in each MovementGroup class.
@@ -75,12 +79,3 @@ class MovementGroup(XMLObject):
     return sorted([[sorted(x[0], lambda a,b:cmp(a.getId(), b.getId())), x[1]] \
                    for x in self._separate(movement_list)],
                   lambda a,b: cmp(a[0][0].getId(), b[0][0].getId()))
-
-  def test(self, object, property_dict, **kw):
-    raise NotImplementedError
-
-  def testToUpdate(self, object, property_dict, **kw):
-    if self.test(object, property_dict, **kw):
-      return True, property_dict
-    else:
-      return False, property_dict
diff --git a/product/ERP5/Document/OrderBuilder.py b/product/ERP5/Document/OrderBuilder.py
index 1fdc226d5b..993f1ed2bb 100644
--- a/product/ERP5/Document/OrderBuilder.py
+++ b/product/ERP5/Document/OrderBuilder.py
@@ -235,12 +235,12 @@ class OrderBuilder(XMLObject, Amount, Predicate):
     my_root_group.append(movement_list)
     return my_root_group
 
-  def _testToUpdate(self, instance, movement_group_list,
+  def _test(self, instance, movement_group_list,
                     divergence_list):
     result = True
     new_property_dict = {}
     for movement_group in movement_group_list:
-      tmp_result, tmp_property_dict = movement_group.testToUpdate(
+      tmp_result, tmp_property_dict = movement_group.test(
         instance, divergence_list)
       if tmp_result == False:
         result = tmp_result
@@ -266,7 +266,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
         instance_list.sort(lambda a,b:cmp(b.getId()==original_id,
                                           a.getId()==original_id))
       for instance_to_update in instance_list:
-        result, property_dict = self._testToUpdate(
+        result, property_dict = self._test(
           instance_to_update, movement_group_list, divergence_list)
         if result == True:
           instance = instance_to_update
diff --git a/product/ERP5/Document/OrderMovementGroup.py b/product/ERP5/Document/OrderMovementGroup.py
index 1e3d69afa3..b97b8d5db5 100644
--- a/product/ERP5/Document/OrderMovementGroup.py
+++ b/product/ERP5/Document/OrderMovementGroup.py
@@ -44,7 +44,7 @@ class OrderMovementGroup(MovementGroup):
     property_dict['causality'] = order_relative_url
     return property_dict
 
-  def testToUpdate(self, movement, property_dict, **kw):
+  def test(self, movement, property_dict, **kw):
     if movement.getCausality() == property_dict['causality']:
       return True, property_dict
     else:
diff --git a/product/ERP5/Document/ParentExplanationMovementGroup.py b/product/ERP5/Document/ParentExplanationMovementGroup.py
index 9daca66ebf..d356a1fb4a 100644
--- a/product/ERP5/Document/ParentExplanationMovementGroup.py
+++ b/product/ERP5/Document/ParentExplanationMovementGroup.py
@@ -45,6 +45,9 @@ class ParentExplanationMovementGroup(MovementGroup):
     property_dict['parent_explanation_value'] = parent_explanation_value
     return property_dict
 
-  def test(self, object, property_dict, property_list=None, **kw):
-    return object.getParentExplanationValue() == \
-           property_dict['parent_explanation_value']
+  def test(self, object, property_dict, **kw):
+    if object.getParentExplanationValue() == \
+       property_dict['parent_explanation_value']:
+      return True, property_dict
+    else:
+      return False, property_dict
diff --git a/product/ERP5/Document/PropertyMovementGroup.py b/product/ERP5/Document/PropertyMovementGroup.py
index b5817bcd49..2f469538f9 100644
--- a/product/ERP5/Document/PropertyMovementGroup.py
+++ b/product/ERP5/Document/PropertyMovementGroup.py
@@ -52,5 +52,5 @@ class PropertyMovementGroup(MovementGroup):
       target_property_list = self.getTestedPropertyList()
     for prop in target_property_list:
       if property_dict[prop] != object.getProperty(prop, None):
-        return False
-    return True
+        return False, property_dict
+    return True, property_dict
diff --git a/product/ERP5/Document/QuantitySignMovementGroup.py b/product/ERP5/Document/QuantitySignMovementGroup.py
index a47abe9bb8..e27e175495 100644
--- a/product/ERP5/Document/QuantitySignMovementGroup.py
+++ b/product/ERP5/Document/QuantitySignMovementGroup.py
@@ -65,17 +65,6 @@ class QuantitySignMovementGroup(MovementGroup):
         ]
 
   def test(self, object, property_dict, **kw):
-    quantity = object.getQuantity()
-    sign1 = property_dict['quantity_sign']
-    sign2 = cmp(quantity, 0)
-    if sign2 == 0:
-      return 1
-    if sign1 == 0:
-      property_dict['quantity_sign'] = sign2
-      return 1
-    return sign1 == sign2
-
-  def testToUpdate(self, object, property_dict, **kw):
     if object.getQuantitySign() == property_dict['quantity_sign']:
       return True, property_dict
     else:
diff --git a/product/ERP5/Document/RequirementMovementGroup.py b/product/ERP5/Document/RequirementMovementGroup.py
index 996748307a..b0fc91ec8c 100644
--- a/product/ERP5/Document/RequirementMovementGroup.py
+++ b/product/ERP5/Document/RequirementMovementGroup.py
@@ -38,7 +38,7 @@ class RequirementMovementGroup(MovementGroup):
   def _getPropertyDict(self, movement, **kw):
     return {'requirement':self._getRequirementList(movement)}
 
-  def testToUpdate(self, movement, property_dict, **kw):
+  def test(self, movement, property_dict, **kw):
     # We can always update
     return True, property_dict
 
diff --git a/product/ERP5/Document/RootAppliedRuleCausalityMovementGroup.py b/product/ERP5/Document/RootAppliedRuleCausalityMovementGroup.py
index faf1c1c230..99c4ff0c27 100644
--- a/product/ERP5/Document/RootAppliedRuleCausalityMovementGroup.py
+++ b/product/ERP5/Document/RootAppliedRuleCausalityMovementGroup.py
@@ -44,7 +44,7 @@ class RootAppliedRuleCausalityMovementGroup(MovementGroup):
     property_dict['root_causality_value_list'] = [root_causality_value]
     return property_dict
 
-  def testToUpdate(self, movement, property_dict, **kw):
+  def test(self, movement, property_dict, **kw):
     # We can always update
     return True, property_dict
 
diff --git a/product/ERP5/Document/SplitMovementGroup.py b/product/ERP5/Document/SplitMovementGroup.py
index becdb685d7..02aa9422fa 100644
--- a/product/ERP5/Document/SplitMovementGroup.py
+++ b/product/ERP5/Document/SplitMovementGroup.py
@@ -38,7 +38,7 @@ class SplitMovementGroup(MovementGroup):
   def _getPropertyDict(self, movement, **kw):
     return {}
 
-  def testToUpdate(self, object, property_dict, **kw):
+  def test(self, object, property_dict, **kw):
     return True, property_dict
 
   def _separate(self, movement_list):
diff --git a/product/ERP5/Document/TitleMovementGroup.py b/product/ERP5/Document/TitleMovementGroup.py
index 00e2355849..5f6823fa5f 100644
--- a/product/ERP5/Document/TitleMovementGroup.py
+++ b/product/ERP5/Document/TitleMovementGroup.py
@@ -41,9 +41,6 @@ class TitleMovementGroup(MovementGroup):
     return property_dict
 
   def test(self, object, property_dict, **kw):
-    return self._getTitle(object) == property_dict['title']
-
-  def testToUpdate(self, object, property_dict, **kw):
     # If title is different, we want to update existing object instead
     # of creating a new one.
     return True, property_dict
diff --git a/product/ERP5/Document/VariantMovementGroup.py b/product/ERP5/Document/VariantMovementGroup.py
index bce5975769..b0ae4dd9d6 100644
--- a/product/ERP5/Document/VariantMovementGroup.py
+++ b/product/ERP5/Document/VariantMovementGroup.py
@@ -49,4 +49,7 @@ class VariantMovementGroup(MovementGroup):
     if category_list is None:
       category_list = []
     category_list.sort()
-    return property_dict['variation_category_list'] == category_list
+    if property_dict['variation_category_list'] == category_list:
+      return True, property_dict
+    else:
+      return False, property_dict
diff --git a/product/ERP5/MovementGroup.py b/product/ERP5/MovementGroup.py
index 08fe72de01..7b8a675606 100644
--- a/product/ERP5/MovementGroup.py
+++ b/product/ERP5/MovementGroup.py
@@ -132,7 +132,7 @@ class MovementGroupNode:
     else:
       return movement
 
-  def testToUpdate(self, movement, divergence_list):
+  def test(self, movement, divergence_list):
     # Try to check if movement is updatable or not.
     #
     # 1. if Divergence has no scope: update anyway.
@@ -155,7 +155,7 @@ class MovementGroupNode:
           if not len(related_divergence_list):
             return True, {}
           property_list = [x.tested_property for x in related_divergence_list]
-      return self._movement_group.testToUpdate(movement, self._property_dict,
+      return self._movement_group.test(movement, self._property_dict,
                                                property_list=property_list)
     else:
       return True, {}
-- 
2.30.9