From d678051b54305433b183016d1699ae65c5f29121 Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Mon, 24 Jan 2011 15:34:10 +0000
Subject: [PATCH] Unify behaviour for all those scripts. use same script to
 interrogate tracking_list, then get the object targeted by script Owner,
 Site, Resource, or VariationCategories

This will improve consistency in UI because at_date parameter is handled in same way
for all of displayed properties.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42630 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../erp5_item/Item_getAffectationList.xml     | 87 +++++++++++++++++++
 .../erp5_item/Item_getCurrentOwnerValue.xml   | 11 +--
 .../erp5_item/Item_getCurrentSiteValue.xml    | 18 +---
 .../erp5_item/Item_getResourceValue.xml       | 25 +-----
 .../Item_getVariationCategoryList.xml         | 23 +----
 .../Item_getVariationCategoryTitleList.xml    | 18 +---
 ...Item_getVariationRangeCategoryItemList.xml | 28 +-----
 bt5/erp5_item/bt/revision                     |  2 +-
 8 files changed, 104 insertions(+), 108 deletions(-)
 create mode 100644 bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getAffectationList.xml

diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getAffectationList.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getAffectationList.xml
new file mode 100644
index 0000000000..875fbd9f3a
--- /dev/null
+++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getAffectationList.xml
@@ -0,0 +1,87 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_asgns</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>name_container</string> </key>
+                                <value> <string>container</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_context</string> </key>
+                                <value> <string>context</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_m_self</string> </key>
+                                <value> <string>script</string> </value>
+                            </item>
+                            <item>
+                                <key> <string>name_subpath</string> </key>
+                                <value> <string>traverse_subpath</string> </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>_body</string> </key>
+            <value> <string>"""Helper script used by many scripts Item_get*(Value|Title) used for UI\n
+It helps to improve consistency between all those scripts\n
+"""\n
+portal = context.getPortalObject()\n
+\n
+default_at_date = False\n
+if at_date is None:\n
+  default_at_date = True\n
+  at_date = DateTime()\n
+\n
+sql_kw = {\'item\': context.getRelativeUrl(),\n
+          \'at_date\': at_date}\n
+\n
+affectation_list = portal.portal_simulation.getCurrentTrackingList(**sql_kw)\n
+\n
+if not affectation_list:\n
+  if default_at_date:\n
+    del kw[\'at_date\']\n
+  affectation_list = portal.portal_simulation.getFutureTrackingList(**sql_kw)\n
+\n
+return affectation_list\n
+</string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>at_date=None, **kw</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Item_getAffectationList</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentOwnerValue.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentOwnerValue.xml
index 4d524347d9..4f0143bdec 100644
--- a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentOwnerValue.xml
+++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentOwnerValue.xml
@@ -50,15 +50,8 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>from DateTime import DateTime\n
-portal = context.getPortalObject()\n
-\n
-last_affectation_list = portal.portal_simulation.getCurrentTrackingList(\n
-                             item=context.getRelativeUrl(), at_date=at_date)\n
-\n
-if not last_affectation_list:\n
-  last_affectation_list = portal.portal_simulation.getFutureTrackingList(\n
-                             item=context.getRelativeUrl(), at_date=at_date)\n
+            <value> <string>portal = context.getPortalObject()\n
+last_affectation_list = context.Item_getAffectationList(**kw)\n
 \n
 if last_affectation_list and last_affectation_list[0].section_uid:\n
   return portal.portal_catalog.getObject(last_affectation_list[0].section_uid)\n
diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentSiteValue.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentSiteValue.xml
index ecadd29a05..b254f82ff5 100644
--- a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentSiteValue.xml
+++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getCurrentSiteValue.xml
@@ -51,22 +51,10 @@
         <item>
             <key> <string>_body</string> </key>
             <value> <string>portal = context.getPortalObject()\n
+last_affectation_list = context.Item_getAffectationList(**kw)\n
 \n
-if at_date is None:\n
-  at_date = DateTime()\n
-\n
-last_affectation_list = portal.portal_simulation.getCurrentTrackingList(\n
-                            item=context.getRelativeUrl(), at_date=at_date)\n
-\n
-if not last_affectation_list:\n
-  last_affectation_list = portal.portal_simulation.getFutureTrackingList(\n
-                            item=context.getRelativeUrl())\n
-if not last_affectation_list:\n
-  return None\n
-\n
-if last_affectation_list[0].node_uid is not None:\n
-  site = portal.portal_catalog.getObject(last_affectation_list[0].node_uid)\n
-  return site\n
+if last_affectation_list and last_affectation_list[0].node_uid is not None:\n
+  return portal.portal_catalog.getObject(last_affectation_list[0].node_uid)\n
 \n
 return None\n
 </string> </value>
diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getResourceValue.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getResourceValue.xml
index 52369fd19e..968bef1a69 100644
--- a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getResourceValue.xml
+++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getResourceValue.xml
@@ -50,29 +50,10 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>from DateTime import DateTime\n
-portal = context.getPortalObject()\n
+            <value> <string>portal = context.getPortalObject()\n
+last_affectation_list = context.Item_getAffectationList(**kw)\n
 \n
-default_at_date = False\n
-if at_date is None:\n
-  default_at_date = True\n
-  at_date = DateTime()\n
-\n
-kw[\'at_date\'] = at_date\n
-kw[\'item\'] = context.getRelativeUrl()\n
-\n
-last_affectation_list = portal.portal_simulation.getCurrentTrackingList(**kw)\n
-\n
-if kw.get(\'src__\',0):\n
-  return last_affectation_list\n
-\n
-if not last_affectation_list:\n
-  # Falback in Future inventory\n
-  if default_at_date:\n
-    del kw[\'at_date\']\n
-  last_affectation_list = portal.portal_simulation.getFutureTrackingList(**kw)\n
-\n
-if len(last_affectation_list):\n
+if last_affectation_list:\n
   last_affectation = last_affectation_list[0]\n
   if last_affectation.resource_uid is not None:\n
     resource_value = portal.portal_catalog.getObject(last_affectation.resource_uid)\n
diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryList.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryList.xml
index 5aa696bee7..958c93e7cb 100644
--- a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryList.xml
+++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryList.xml
@@ -50,27 +50,8 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>from DateTime import DateTime\n
-portal = context.getPortalObject()\n
-\n
-default_at_date = False\n
-if at_date is None:\n
-  default_at_date = True\n
-  at_date = DateTime()\n
-kw[\'at_date\'] = at_date\n
-\n
-kw[\'item\'] = context.getRelativeUrl()\n
-\n
-last_affectation_list = portal.portal_simulation.getCurrentTrackingList(**kw)\n
-\n
-if kw.get(\'src__\',0):\n
-  return last_affectation_list\n
-\n
-if not last_affectation_list:\n
-  # Falback in Future inventory\n
-  if default_at_date:\n
-    del kw[\'at_date\']\n
-  last_affectation_list = portal.portal_simulation.getFutureTrackingList(**kw)\n
+            <value> <string>portal = context.getPortalObject()\n
+last_affectation_list = context.Item_getAffectationList(**kw)\n
 \n
 if len(last_affectation_list):\n
   last_affectation = last_affectation_list[0]\n
diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryTitleList.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryTitleList.xml
index 4af5a65786..0789a24d63 100644
--- a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryTitleList.xml
+++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationCategoryTitleList.xml
@@ -50,21 +50,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>from DateTime import DateTime\n
-portal = context.getPortalObject()\n
-\n
-kw[\'at_date\'] = DateTime()\n
-kw[\'item\'] = context.getRelativeUrl()\n
-\n
-last_affectation_list = portal.portal_simulation.getCurrentTrackingList(**kw)\n
-\n
-if kw.get(\'src__\',0):\n
-  return last_affectation_list\n
-\n
-if not last_affectation_list:\n
-  # Falback in Future inventory\n
-  last_affectation_list = portal.portal_simulation.getFutureTrackingList(**kw)\n
-\n
+            <value> <string>last_affectation_list = context.Item_getAffectationList(**kw)\n
 if len(last_affectation_list):\n
   last_affectation = last_affectation_list[0]\n
   if last_affectation.delivery_uid is not None:\n
@@ -78,7 +64,7 @@ return []\n
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>current=1,**kw</string> </value>
+            <value> <string>**kw</string> </value>
         </item>
         <item>
             <key> <string>id</string> </key>
diff --git a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationRangeCategoryItemList.xml b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationRangeCategoryItemList.xml
index aa6d9b2f8e..b206641929 100644
--- a/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationRangeCategoryItemList.xml
+++ b/bt5/erp5_item/SkinTemplateItem/portal_skins/erp5_item/Item_getVariationRangeCategoryItemList.xml
@@ -50,29 +50,9 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>from DateTime import DateTime\n
-portal = context.getPortalObject()\n
-\n
-default_at_date = False\n
-if at_date is None:\n
-  default_at_date = True\n
-  at_date = DateTime()\n
-kw[\'at_date\'] = at_date\n
-\n
-kw[\'item\'] = context.getRelativeUrl()\n
-\n
-last_affectation_list = portal.portal_simulation.getCurrentTrackingList(**kw)\n
-\n
-if kw.get(\'src__\',0):\n
-  return last_affectation_list\n
-\n
-if not last_affectation_list:\n
-  # Falback in Future inventory\n
-  if default_at_date:\n
-    del kw[\'at_date\']\n
-  last_affectation_list = portal.portal_simulation.getFutureTrackingList(**kw)\n
-\n
-if len(last_affectation_list):\n
+            <value> <string>portal = context.getPortalObject()\n
+last_affectation_list = context.Item_getAffectationList(**kw)\n
+if last_affectation_list:\n
   last_affectation = last_affectation_list[0]\n
   if last_affectation.delivery_uid is not None:\n
     movement = portal.portal_catalog.getObject(last_affectation.delivery_uid)\n
@@ -83,7 +63,7 @@ return []\n
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>at_date=None, **kw</string> </value>
+            <value> <string>**kw</string> </value>
         </item>
         <item>
             <key> <string>id</string> </key>
diff --git a/bt5/erp5_item/bt/revision b/bt5/erp5_item/bt/revision
index ac7cd1ac70..c2567dc4fb 100644
--- a/bt5/erp5_item/bt/revision
+++ b/bt5/erp5_item/bt/revision
@@ -1 +1 @@
-279
\ No newline at end of file
+280
\ No newline at end of file
-- 
2.30.9