From cd37571315df52ea5cd439ccf90e1f47a29f9d2f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Nowak?= <luke@nexedi.com>
Date: Tue, 21 Jul 2009 09:04:38 +0000
Subject: [PATCH]  - support DummyMovement to be in DummyDelivery  - set up is
 as movement in orders and deliveries

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@28117 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../DocumentTemplateItem/DummyMovement.py     | 43 +++++++++++++------
 .../portal_types/Dummy%20Movement.xml         | 28 +++++-------
 bt5/erp5_dummy_movement/bt/version            |  2 +-
 3 files changed, 40 insertions(+), 33 deletions(-)

diff --git a/bt5/erp5_dummy_movement/DocumentTemplateItem/DummyMovement.py b/bt5/erp5_dummy_movement/DocumentTemplateItem/DummyMovement.py
index e7d0f13b75..e2d3a7d8a1 100644
--- a/bt5/erp5_dummy_movement/DocumentTemplateItem/DummyMovement.py
+++ b/bt5/erp5_dummy_movement/DocumentTemplateItem/DummyMovement.py
@@ -1,7 +1,9 @@
+# -*- coding: utf-8 -*-
 ##############################################################################
 #
-# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
+# Copyright (c) 2006 Nexedi SA and Contributors. All Rights Reserved.
 #                    Jerome Perrin <jerome@nexedi.com>
+#                    Łukasz Nowak <luke@nexedi.com>
 #
 # WARNING: This program as such is intended to be used by professional
 # programmers who take the whole responsability of assessing all potential
@@ -32,8 +34,8 @@ from Products.ERP5.Document.Movement import Movement
 
 class DummyMovement(Movement):
   """Dummy Movement for testing purposes."""
-  meta_type = 'ERP5 Movement'
-  portal_type = 'Movement'
+  meta_type = 'ERP5 Dummy Movement'
+  portal_type = 'Dummy Movement'
   add_permission = Permissions.AddPortalContent
   isPortalContent = 1
   isRADContent = 1
@@ -61,25 +63,38 @@ class DummyMovement(Movement):
     """Our dummy movement are always accountable."""
     return getattr(self, 'is_accountable', 1)
 
+  def _getPropertyDirectlyOrFromDummyDelivery(self, property, default=None):
+    """Returns property from delivery, in case if in Dummy Delivery, or movement"""
+    if self.getParentValue().getPortalType() == 'Dummy Delivery':
+      return self.getParentValue().getSimulationState()
+    return getattr(self, property, default)
+
   def getSimulationState(self):
-    """Directly returns a simulation state."""
-    return getattr(self, 'simulation_state', 'draft')
-  
+    return self._getPropertyDirectlyOrFromDummyDelivery(
+        'simulation_state', 'draft')
+
   def setSimulationState(self, state):
-    """Directly sets a simulation state."""
-    self.simulation_state = state
+    """Directly sets a simulation state if not in Dummy Delivery."""
+    if self.getParentValue().getPortalType() != 'Dummy Delivery':
+      self.simulation_state = state
+    else:
+      raise ValueError
 
   def getCausalityState(self):
-    """Directly returns a causality state."""
-    return getattr(self, 'simulation_state', 'draft')
-  
+    return self._getPropertyDirectlyOrFromDummyDelivery(
+        'causality_state', 'draft')
+
   def setCausalityState(self, state):
     """Directly sets a causality state."""
-    self.causality_state = state
-    
+    if self.getParentValue().getPortalType() != 'Dummy Delivery':
+      self.simulation_state = state
+    else:
+      raise ValueError
+
   def getDeliveryValue(self):
     """A dummy movement doesn't have a delivery relation, so return self as delivery.
     """
     return self
 
-
+  def hasCellContent(self):
+    return False
diff --git a/bt5/erp5_dummy_movement/PortalTypeTemplateItem/portal_types/Dummy%20Movement.xml b/bt5/erp5_dummy_movement/PortalTypeTemplateItem/portal_types/Dummy%20Movement.xml
index 92ecad4af2..8e41d4f4f7 100644
--- a/bt5/erp5_dummy_movement/PortalTypeTemplateItem/portal_types/Dummy%20Movement.xml
+++ b/bt5/erp5_dummy_movement/PortalTypeTemplateItem/portal_types/Dummy%20Movement.xml
@@ -3,21 +3,12 @@
   <record id="1" aka="AAAAAAAAAAE=">
     <pickle>
       <tuple>
-        <tuple>
-          <string>Products.ERP5Type.ERP5Type</string>
-          <string>ERP5TypeInformation</string>
-        </tuple>
-        <none/>
+        <global name="ERP5TypeInformation" module="Products.ERP5Type.ERP5Type"/>
+        <tuple/>
       </tuple>
     </pickle>
     <pickle>
       <dictionary>
-        <item>
-            <key> <string>__ac_local_roles__</string> </key>
-            <value>
-              <none/>
-            </value>
-        </item>
         <item>
             <key> <string>_actions</string> </key>
             <value>
@@ -30,12 +21,6 @@
               <dictionary/>
             </value>
         </item>
-        <item>
-            <key> <string>_owner</string> </key>
-            <value>
-              <none/>
-            </value>
-        </item>
         <item>
             <key> <string>_roles</string> </key>
             <value>
@@ -81,7 +66,10 @@
         <item>
             <key> <string>group_list</string> </key>
             <value>
-              <tuple/>
+              <tuple>
+                <string>delivery_movement</string>
+                <string>order_movement</string>
+              </tuple>
             </value>
         </item>
         <item>
@@ -98,6 +86,10 @@
             <key> <string>init_script</string> </key>
             <value> <string></string> </value>
         </item>
+        <item>
+            <key> <string>permission</string> </key>
+            <value> <string></string> </value>
+        </item>
         <item>
             <key> <string>property_sheet_list</string> </key>
             <value>
diff --git a/bt5/erp5_dummy_movement/bt/version b/bt5/erp5_dummy_movement/bt/version
index ceab6e11ec..2f4536184b 100644
--- a/bt5/erp5_dummy_movement/bt/version
+++ b/bt5/erp5_dummy_movement/bt/version
@@ -1 +1 @@
-0.1
\ No newline at end of file
+0.2
\ No newline at end of file
-- 
2.30.9