From a79ec10be4343c6108792f697e5516dfe9f52c46 Mon Sep 17 00:00:00 2001
From: Romain Courteaud <romain@nexedi.com>
Date: Wed, 13 Sep 2006 12:50:19 +0000
Subject: [PATCH] Copy properties on the Simulation Movement, instead of using
 acquisition. Thanks to Rafael Monnerat.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@9866 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/OrderRule.py           | 54 +++++++++++---------
 product/ERP5/Document/ProductionOrderRule.py | 41 ++++++++++-----
 2 files changed, 57 insertions(+), 38 deletions(-)

diff --git a/product/ERP5/Document/OrderRule.py b/product/ERP5/Document/OrderRule.py
index 30f3e8becf..dbba425f0b 100644
--- a/product/ERP5/Document/OrderRule.py
+++ b/product/ERP5/Document/OrderRule.py
@@ -95,10 +95,11 @@ class OrderRule(DeliveryRule):
         else:
           existing_movement_list.append(movement)
           immutable_movement_list.append(movement)
-      
+       
       # Create or modify movements
       for movement in order_movement_list:
         related_order = movement.getOrderRelatedValue()
+        property_dict = self._getExpandablePropertyDict(applied_rule, movement)      
         if related_order is None:
           if movement.getParentUid() == movement.getExplanationUid():
             # We are on a line
@@ -107,7 +108,6 @@ class OrderRule(DeliveryRule):
             # We are on a cell
             new_id = "%s_%s" % (movement.getParentId(), movement.getId())
           # Generate a simulation movement
-          LOG("OrderRule, expand", WARNING, "Hardcoded state list")
           applied_rule.newContent(
               portal_type=movement_type,
               id=new_id,
@@ -115,34 +115,15 @@ class OrderRule(DeliveryRule):
               order_ratio=1,
               delivery_ratio=1,
               deliverable=1,
-#               source=movement.getSource(),
-#               source_section=movement.getSourceSection(),
-#               destination=movement.getDestination(),
-#               destination_section=movement.getDestinationSection(),
-#               quantity=movement.getQuantity(),
-#               resource=movement.getResource(),
-#               variation_category_list=movement.getVariationCategoryList(),
-#               variation_property_dict=movement.getVariationPropertyDict(),
-#               start_date=movement.getStartDate(),
-#               stop_date=movement.getStopDate(),
-              **kw)
-        
+              **property_dict )
+          
         elif related_order in existing_movement_list:
           if related_order not in immutable_movement_list:
             # modification allowed
             related_order.edit(
               order_value=movement,
-#               source=movement.getSource(),
-#               source_section=movement.getSourceSection(),
-#               destination=movement.getDestination(),
-#               destination_section=movement.getDestinationSection(),
-#               quantity=movement.getQuantity(),
-#               resource=movement.getResource(),
-#               variation_category_list=movement.getVariationCategoryList(),
-#               variation_property_dict=movement.getVariationPropertyDict(),
-#               start_date=movement.getStartDate(),
-#               stop_date=movement.getStopDate(),
-              **kw)
+                **property_dict)
+            
             #related_order.setLastExpandSimulationState(order.getSimulationState())
             
           else:
@@ -169,3 +150,26 @@ class OrderRule(DeliveryRule):
     Checks that the movement is divergent
     """
     return Rule.isDivergent(self, movement)
+
+  security.declareProtected(Permissions.AccessContentsInformation,
+                            '_getExpandablePropertyDict')
+  def _getExpandablePropertyDict(self, applied_rule, movement,
+                                 default_property_list=None, **kw):
+    """
+    Return a Dictionary with the Properties used to edit 
+    the simulation movement
+    """
+    property_dict = {}
+
+    if default_property_list is None:
+      LOG("Order Rule , _getPropertiesTo", WARNING,
+                                "Hardcoded properties set")
+      default_property_list = (
+        'source_section', 'destination_section', 'source',
+        'destination', 'resource', 'variation_category_list',
+        'aggregate_list', 'start_date', 'stop_date')
+  
+      for prop in default_property_list:
+         property_dict[prop] = movement.getProperty(prop)
+       
+    return property_dict
diff --git a/product/ERP5/Document/ProductionOrderRule.py b/product/ERP5/Document/ProductionOrderRule.py
index 43e4d94669..9812ef654b 100644
--- a/product/ERP5/Document/ProductionOrderRule.py
+++ b/product/ERP5/Document/ProductionOrderRule.py
@@ -33,7 +33,7 @@ from Products.ERP5.Document.OrderRule import OrderRule
 from Products.ERP5.Document.TransformationSourcingRule import\
                                             TransformationSourcingRuleMixin
 
-from zLOG import LOG
+from zLOG import LOG, WARNING
 
 class ProductionOrderRule(OrderRule):
     """
@@ -60,14 +60,26 @@ class ProductionOrderRule(OrderRule):
                       )
 
     # Simulation workflow
-    security.declareProtected(Permissions.ModifyPortalContent, 'expand')
-    def expand(self, applied_rule, force=0, **kw):
+    security.declareProtected(Permissions.AccessContentsInformation,
+                              '_getExpandablePropertyDict')
+    def _getExpandablePropertyDict(self, applied_rule, movement, 
+                                   default_property_list=None, **kw):
       """
-        Expands the current movement downward.
-        -> new status -> expanded
-        An applied rule can be expanded only if its parent movement
-        is expanded.
+      Return a Dictionary with the Properties used to edit 
+      the simulation movement.
       """
+      property_dict = {}
+
+      if default_property_list is None:
+        LOG("Order Rule , _getExpandablePropertyDict", WARNING,
+            "Hardcoded properties set")
+        default_property_list = (
+          'destination_section',
+          'destination', 'resource', 
+          'variation_category_list',
+          'aggregate_list',
+          'start_date', 'stop_date')
+    
       supply_chain = self.getSupplyChain(applied_rule)
       # We got a supply chain
       # Try to get the last SupplyLink
@@ -76,14 +88,17 @@ class ProductionOrderRule(OrderRule):
       # Now, we have to generate Simulation Movement, in order to
       # create a ProductionPackingList.
       destination_node = last_link.getDestinationValue()
-      source_value = destination_node.getDestinationValue()
-      source_section_value = last_link.getDestinationSectionValue()
+      source_value = destination_node.getDestination()
+      source_section_value = last_link.getDestinationSection()
       if source_value is not None:
-        kw["source_value"] = source_value
+        property_dict["source"] = source_value
       if source_section_value is not None:
-        kw["source_section_value"] = source_section_value
-      # Pass to base class
-      OrderRule.expand(self, applied_rule, force=force, **kw)
+        property_dict["source_section"] = source_section_value
+    
+      for prop in default_property_list:
+        property_dict[prop] = movement.getProperty(prop)
+    
+      return property_dict
 
 from Products.ERP5Type.Utils import monkeyPatch
 monkeyPatch(TransformationSourcingRuleMixin, ProductionOrderRule)
-- 
2.30.9