From b8f9ecb71e7ee5b195e0c932fbadc0d496fece67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Mon, 17 Aug 2009 13:54:42 +0000
Subject: [PATCH]  - use order link to match simulation movements with
 prevision for root rules, remove fixed todos  - be consistent - use _list for
 order and delivery category property

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28417 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/BPMDeliveryRule.py |  6 ++----
 product/ERP5/Document/BPMOrderRule.py    |  4 +---
 product/ERP5/Document/BPMRule.py         | 14 ++++++++++----
 product/ERP5/tests/testBPMEvaluation.py  |  9 ++++++---
 4 files changed, 19 insertions(+), 14 deletions(-)

diff --git a/product/ERP5/Document/BPMDeliveryRule.py b/product/ERP5/Document/BPMDeliveryRule.py
index 47f5bf86d6..cf68c88d92 100644
--- a/product/ERP5/Document/BPMDeliveryRule.py
+++ b/product/ERP5/Document/BPMDeliveryRule.py
@@ -38,8 +38,6 @@ class BPMDeliveryRule(BPMRule):
     DISCLAIMER: Refer to BPMRule docstring disclaimer.
 
     This is BPM enabled Delivery Rule.
-
-    FIXME: override _getCompensatedMovementList to match per order link
   """
 
   # CMF Type Definition
@@ -64,7 +62,7 @@ class BPMDeliveryRule(BPMRule):
       business_path, current_property_dict):
     """Delivery specific update dict"""
     return {
-      'order_value': movement,
-      'delivery_value': movement,
+      'order_list': [movement.getRelativeUrl()],
+      'delivery_list': [movement.getRelativeUrl()],
       'deliverable': 1,
     }
diff --git a/product/ERP5/Document/BPMOrderRule.py b/product/ERP5/Document/BPMOrderRule.py
index 7ab9ee293e..0897c4387f 100644
--- a/product/ERP5/Document/BPMOrderRule.py
+++ b/product/ERP5/Document/BPMOrderRule.py
@@ -38,8 +38,6 @@ class BPMOrderRule(BPMDeliveryRule):
     DISCLAIMER: Refer to BPMRule docstring disclaimer.
 
     This is BPM enabled Order Rule.
-
-    FIXME: override _getCompensatedMovementList to match per order link
   """
   # CMF Type Definition
   meta_type = 'ERP5 BPM Order Rule'
@@ -63,6 +61,6 @@ class BPMOrderRule(BPMDeliveryRule):
       business_path, current_property_dict):
     """Order rule specific update dictionary"""
     return {
-      'order_value': movement,
+      'order_list': [movement.getRelativeUrl()],
       'deliverable': 1,
     }
diff --git a/product/ERP5/Document/BPMRule.py b/product/ERP5/Document/BPMRule.py
index ff4107ef0a..9f9c69a33c 100644
--- a/product/ERP5/Document/BPMRule.py
+++ b/product/ERP5/Document/BPMRule.py
@@ -260,11 +260,17 @@ class BPMRule(Predicate, XMLObject):
     for prevision in prevision_list:
       p_matched_list = []
       for movement in non_matched_list:
-        for prop in self.getMatchingPropertyList():
-          if prevision.get(prop) != movement.getProperty(prop):
-            break
+        if 'order_list' in prevision:
+          # applied rule is root, use order link to find movement
+          if movement.getOrder() ==  prevision.get('order_list', [''])[0]:
+            p_matched_list.append(movement)
         else:
-          p_matched_list.append(movement)
+          # applied rule is not root one, match
+          for prop in self.getMatchingPropertyList():
+            if prevision.get(prop) != movement.getProperty(prop):
+              break
+          else:
+            p_matched_list.append(movement)
 
       # Movements exist, we'll try to make them match the prevision
       if p_matched_list != []:
diff --git a/product/ERP5/tests/testBPMEvaluation.py b/product/ERP5/tests/testBPMEvaluation.py
index ad93de51c8..a2c9a17803 100644
--- a/product/ERP5/tests/testBPMEvaluation.py
+++ b/product/ERP5/tests/testBPMEvaluation.py
@@ -39,6 +39,12 @@ It is advised to *NOT* remove erp5_administration.
 TODOs:
   * avoid duplication of code when possible
   * implement tests wisely, to support at least both BPM cases
+
+Scenarios to cover:
+
+  * unify root rules (BPMOrderRule, BPMDeliveryRule, etc) tests - they share
+    a lot of code
+  * test case of splitting for root rules
 """
 import unittest
 
@@ -304,9 +310,6 @@ class TestOrder(TestBPMEvaluationMixin):
     self._checkOrderBPMSimulation()
 
   def test_planning_line_edit_add_same_resource_than_order(self):
-    # TODO: this test fails because BPMOrderRule do not matches movement using
-    # order link, this have to be done in similar way like OrderRule and
-    # DeliveryRule work
     self.test_planning_line_edit_add_same_resource()
     self.order.order()
     self.stepTic()
-- 
2.30.9