From a110654f30ea529018a4605af0fb5b74cb314382 Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Tue, 2 Mar 2010 13:33:17 +0000
Subject: [PATCH] add 'Property Mapping' portal type, describes how properties
 or categories are mapped from simulation movements to delivery documents, eg.
 use source as destination, use destination as source, use quantity as
 -quantity, etc.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33279 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../portal_types/Property%20Mapping/view.xml  | 85 +++++++++++++++++++
 .../portal_types/Property%20Mapping.xml       | 57 +++++++++++++
 bt5/erp5_base/bt/template_action_path_list    |  1 +
 bt5/erp5_base/bt/template_portal_type_id_list |  1 +
 product/ERP5/Document/PropertyMapping.py      | 61 +++++++++++++
 product/ERP5/PropertySheet/PropertyMapping.py | 39 +++++++++
 6 files changed, 244 insertions(+)
 create mode 100644 bt5/erp5_base/ActionTemplateItem/portal_types/Property%20Mapping/view.xml
 create mode 100644 bt5/erp5_base/PortalTypeTemplateItem/portal_types/Property%20Mapping.xml
 create mode 100644 product/ERP5/Document/PropertyMapping.py
 create mode 100644 product/ERP5/PropertySheet/PropertyMapping.py

diff --git a/bt5/erp5_base/ActionTemplateItem/portal_types/Property%20Mapping/view.xml b/bt5/erp5_base/ActionTemplateItem/portal_types/Property%20Mapping/view.xml
new file mode 100644
index 0000000000..b6dc498a1d
--- /dev/null
+++ b/bt5/erp5_base/ActionTemplateItem/portal_types/Property%20Mapping/view.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="ActionInformation" module="Products.CMFCore.ActionInformation"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>action</string> </key>
+            <value>
+              <persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
+            </value>
+        </item>
+        <item>
+            <key> <string>categories</string> </key>
+            <value>
+              <tuple>
+                <string>action_type/object_view</string>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>category</string> </key>
+            <value> <string>object_view</string> </value>
+        </item>
+        <item>
+            <key> <string>condition</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>icon</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>view</string> </value>
+        </item>
+        <item>
+            <key> <string>permissions</string> </key>
+            <value>
+              <tuple>
+                <string>View</string>
+              </tuple>
+            </value>
+        </item>
+        <item>
+            <key> <string>priority</string> </key>
+            <value> <float>1.0</float> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string>View</string> </value>
+        </item>
+        <item>
+            <key> <string>visible</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+  <record id="2" aka="AAAAAAAAAAI=">
+    <pickle>
+      <tuple>
+        <global name="Expression" module="Products.CMFCore.Expression"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>text</string> </key>
+            <value> <string>string:${object_url}/PropertyMapping_view</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_base/PortalTypeTemplateItem/portal_types/Property%20Mapping.xml b/bt5/erp5_base/PortalTypeTemplateItem/portal_types/Property%20Mapping.xml
new file mode 100644
index 0000000000..5b22993e04
--- /dev/null
+++ b/bt5/erp5_base/PortalTypeTemplateItem/portal_types/Property%20Mapping.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="ERP5TypeInformation" module="Products.ERP5Type.ERP5Type"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>acquire_local_roles</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+        <item>
+            <key> <string>content_icon</string> </key>
+            <value> <string>document.gif</string> </value>
+        </item>
+        <item>
+            <key> <string>content_meta_type</string> </key>
+            <value> <string>ERP5 Mapping</string> </value>
+        </item>
+        <item>
+            <key> <string>description</string> </key>
+            <value> <string>Property Mapping object describes how properties or categories are mapped from simulation movements to delivery documents, eg. use source as destination, use destination as source, use quantity as -quantity, etc.</string> </value>
+        </item>
+        <item>
+            <key> <string>factory</string> </key>
+            <value> <string>addPropertyMapping</string> </value>
+        </item>
+        <item>
+            <key> <string>filter_content_types</string> </key>
+            <value> <int>1</int> </value>
+        </item>
+        <item>
+            <key> <string>group_list</string> </key>
+            <value>
+              <tuple/>
+            </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>Property Mapping</string> </value>
+        </item>
+        <item>
+            <key> <string>init_script</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/bt5/erp5_base/bt/template_action_path_list b/bt5/erp5_base/bt/template_action_path_list
index 7a574098f6..6bf32d043c 100644
--- a/bt5/erp5_base/bt/template_action_path_list
+++ b/bt5/erp5_base/bt/template_action_path_list
@@ -68,6 +68,7 @@ Person | view
 Preference | base_preference
 Property Assignment Movement Group | view
 Property Divergence Tester | view
+Property Mapping | view
 Property Movement Group | view
 Quantity Divergence Tester | view
 Quantity Sign Movement Group | view
diff --git a/bt5/erp5_base/bt/template_portal_type_id_list b/bt5/erp5_base/bt/template_portal_type_id_list
index 45cd8d105c..fea98886a5 100644
--- a/bt5/erp5_base/bt/template_portal_type_id_list
+++ b/bt5/erp5_base/bt/template_portal_type_id_list
@@ -38,6 +38,7 @@ Person
 Person Module
 Property Assignment Movement Group
 Property Divergence Tester
+Property Mapping
 Property Movement Group
 Quantity Divergence Tester
 Quantity Sign Movement Group
diff --git a/product/ERP5/Document/PropertyMapping.py b/product/ERP5/Document/PropertyMapping.py
new file mode 100644
index 0000000000..33cceb3603
--- /dev/null
+++ b/product/ERP5/Document/PropertyMapping.py
@@ -0,0 +1,61 @@
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsibility of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# guarantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+##############################################################################
+
+from AccessControl import ClassSecurityInfo
+from Products.ERP5Type import Permissions, PropertySheet
+from Products.ERP5Type.XMLObject import XMLObject
+
+class PropertyMapping(XMLObject):
+  """
+  Property Mapping object describes how properties or categories are
+  mapped, eg. use source as destination, use destination as source, use
+  quantity as -quantity, etc.
+  """
+  meta_type = 'ERP5 Property Mapping'
+  portal_type = 'Property Mapping'
+  add_permission = Permissions.AddPortalContent
+
+  # Declarative security
+  security = ClassSecurityInfo()
+  security.declareObjectProtected(Permissions.AccessContentsInformation)
+
+  # Declarative properties
+  property_sheets = (PropertySheet.Base,
+                     PropertySheet.SimpleItem,
+                     PropertySheet.CategoryCore,
+                     PropertySheet.PropertyMapping)
+
+  security.declareProtected(Permissions.AccessContentsInformation,
+                            'getMappedValue')
+  def getMappedValue(self, document, property):
+    mapping_dict = dict([[x.strip() for x in x.split('|')] \
+                         for x in self.getMappingPropertyList()])
+    mapped_property = mapping_dict.get(property, property)
+    if mapped_property.startswith('-'):
+      return -1 * document.getProperty(mapped_property)
+    else:
+      document.getProperty(mapped_property)
diff --git a/product/ERP5/PropertySheet/PropertyMapping.py b/product/ERP5/PropertySheet/PropertyMapping.py
new file mode 100644
index 0000000000..ffd1e5bd38
--- /dev/null
+++ b/product/ERP5/PropertySheet/PropertyMapping.py
@@ -0,0 +1,39 @@
+##############################################################################
+#
+# Copyright (c) 2010 Nexedi SA and Contributors. All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsibility of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# guarantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+##############################################################################
+
+class PropertyMapping:
+  """
+  Property sheet for Property Mapping class and subclass instances
+  """
+  _properties = (
+    {'id'          : 'mapping_property',
+     'description' : 'List of mapping of properties or categories',
+     'type'        : 'lines',
+     'default'     : [],
+     'multivalued' : 1,
+     'mode'        : 'w' },
+  )
-- 
2.30.9