From db7994cdd8f0c6183332c4a0422ecf08ef97935f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Mon, 5 Oct 2009 15:57:41 +0000
Subject: [PATCH] support function and project in inventory API

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@29415 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Tool/SimulationTool.py           |  17 +-
 ...d_function_uid_from_stock.catalog_keys.xml |   2 +
 .../z_related_function_uid_from_stock.xml     | 152 +++++++++++++++++
 ...ed_project_uid_from_stock.catalog_keys.xml |   2 +
 .../z_related_project_uid_from_stock.xml      | 152 +++++++++++++++++
 ...p_function_uid_from_stock.catalog_keys.xml |   2 +
 ...ict_membership_function_uid_from_stock.xml | 156 ++++++++++++++++++
 ...ip_project_uid_from_stock.catalog_keys.xml |   2 +
 ...rict_membership_project_uid_from_stock.xml | 156 ++++++++++++++++++
 .../related_key_list.xml                      |   4 +
 .../erp5_mysql_innodb_catalog/bt/revision     |   2 +-
 .../bt/template_catalog_method_id_list        |   4 +
 .../bt/template_catalog_related_key_list      |   4 +
 product/ERP5/tests/testInventoryAPI.py        |  86 ++++++++++
 14 files changed, 739 insertions(+), 2 deletions(-)
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.catalog_keys.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.catalog_keys.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.catalog_keys.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.catalog_keys.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.xml

diff --git a/product/ERP5/Tool/SimulationTool.py b/product/ERP5/Tool/SimulationTool.py
index 0b339d2f09..c33d1ace04 100644
--- a/product/ERP5/Tool/SimulationTool.py
+++ b/product/ERP5/Tool/SimulationTool.py
@@ -491,17 +491,21 @@ class SimulationTool(BaseTool):
         # instances
         resource=None, node=None, payment=None,
         section=None, mirror_section=None, item=None,
+        function=None, project=None,
         # used for tracking
         input=0, output=0,
         # categories
         resource_category=None, node_category=None, payment_category=None,
         section_category=None, mirror_section_category=None,
+        function_category=None, project_category=None,
         # categories with strict membership
         resource_category_strict_membership=None,
         node_category_strict_membership=None,
         payment_category_strict_membership=None,
         section_category_strict_membership=None,
         mirror_section_category_strict_membership=None,
+        function_category_strict_membership=None,
+        project_category_strict_membership=None,
         # simulation_state
         strict_simulation_state=0,
         simulation_state=None, transit_simulation_state = None, omit_transit=0,
@@ -512,7 +516,8 @@ class SimulationTool(BaseTool):
         variation_category=None,
         # uids
         resource_uid=None, node_uid=None, section_uid=None, payment_uid=None,
-        mirror_node_uid=None, mirror_section_uid=None,
+        mirror_node_uid=None, mirror_section_uid=None, function_uid=None,
+        project_uid=None,
         # omit input and output
         omit_input=0,
         omit_output=0,
@@ -584,6 +589,8 @@ class SimulationTool(BaseTool):
 
       column_value_dict.set('resource_uid', resource_uid)
       column_value_dict.set('payment_uid', payment_uid)
+      column_value_dict.set('project_uid', project_uid)
+      column_value_dict.set('function_uid', function_uid)
       if column_value_dict.set('section_uid', section_uid):
         sql_kw['section_filtered'] = 1
       column_value_dict.set('node_uid', node_uid)
@@ -593,6 +600,8 @@ class SimulationTool(BaseTool):
       column_value_dict.setUIDList('aggregate_uid', item)
       column_value_dict.setUIDList('node_uid', node)
       column_value_dict.setUIDList('payment_uid', payment)
+      column_value_dict.setUIDList('project_uid', project)
+      column_value_dict.setUIDList('function_uid', function)
       if column_value_dict.setUIDList('section_uid', section):
         sql_kw['section_filtered'] = 1
       column_value_dict.setUIDList('mirror_section_uid', mirror_section)
@@ -606,6 +615,8 @@ class SimulationTool(BaseTool):
       # category membership
       related_key_dict.setUIDList('resource_category_uid', resource_category)
       related_key_dict.setUIDList('node_category_uid', node_category)
+      related_key_dict.setUIDList('project_category_uid', project_category)
+      related_key_dict.setUIDList('function_category_uid', function_category)
       related_key_dict.setUIDList('payment_category_uid', payment_category)
       if related_key_dict.setUIDList('section_category_uid',
                                      section_category):
@@ -617,6 +628,10 @@ class SimulationTool(BaseTool):
                                   resource_category_strict_membership)
       related_key_dict.setUIDList('node_category_strict_membership_uid',
                                   node_category_strict_membership)
+      related_key_dict.setUIDList('project_category_strict_membership_uid',
+                                  project_category_strict_membership)
+      related_key_dict.setUIDList('function_category_strict_membership_uid',
+                                  function_category_strict_membership)
       related_key_dict.setUIDList('payment_category_strict_membership_uid',
                                   payment_category_strict_membership)
       if related_key_dict.setUIDList('section_category_strict_membership_uid',
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.catalog_keys.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.catalog_keys.xml
new file mode 100644
index 0000000000..7d6996cb9c
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.catalog_keys.xml
@@ -0,0 +1,2 @@
+<catalog_method>
+</catalog_method>
\ No newline at end of file
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.xml
new file mode 100644
index 0000000000..db6eb2f324
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_function_uid_from_stock.xml
@@ -0,0 +1,152 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="SQL" module="Products.ZSQLMethods.SQL"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_arg</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="Args" module="Shared.DC.ZRDB.Aqueduct"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_data</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>table_0</string> </key>
+                                <value>
+                                  <dictionary/>
+                                </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>_keys</string> </key>
+                        <value>
+                          <list>
+                            <string>table_0</string>
+                          </list>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>allow_simple_one_argument_traversal</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>arguments_src</string> </key>
+            <value> <string>table_0</string> </value>
+        </item>
+        <item>
+            <key> <string>cache_time_</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+        <item>
+            <key> <string>class_file_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>class_name_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>connection_hook</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>connection_id</string> </key>
+            <value> <string>erp5_sql_connection</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>z_related_function_uid_from_stock</string> </value>
+        </item>
+        <item>
+            <key> <string>max_cache_</string> </key>
+            <value> <int>100</int> </value>
+        </item>
+        <item>
+            <key> <string>max_rows_</string> </key>
+            <value> <int>1000</int> </value>
+        </item>
+        <item>
+            <key> <string>src</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.function_uid
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>template</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="__newobj__" module="copy_reg"/>
+                </klass>
+                <tuple>
+                  <global name="SQL" module="Shared.DC.ZRDB.DA"/>
+                </tuple>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>__name__</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<string>
+
+]]></string> </value>
+                    </item>
+                    <item>
+                        <key> <string>_vars</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>globals</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>raw</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.function_uid
+
+]]></string> </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.catalog_keys.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.catalog_keys.xml
new file mode 100644
index 0000000000..7d6996cb9c
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.catalog_keys.xml
@@ -0,0 +1,2 @@
+<catalog_method>
+</catalog_method>
\ No newline at end of file
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.xml
new file mode 100644
index 0000000000..f85e951e6f
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_project_uid_from_stock.xml
@@ -0,0 +1,152 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="SQL" module="Products.ZSQLMethods.SQL"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_arg</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="Args" module="Shared.DC.ZRDB.Aqueduct"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_data</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>table_0</string> </key>
+                                <value>
+                                  <dictionary/>
+                                </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>_keys</string> </key>
+                        <value>
+                          <list>
+                            <string>table_0</string>
+                          </list>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>allow_simple_one_argument_traversal</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>arguments_src</string> </key>
+            <value> <string>table_0</string> </value>
+        </item>
+        <item>
+            <key> <string>cache_time_</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+        <item>
+            <key> <string>class_file_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>class_name_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>connection_hook</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>connection_id</string> </key>
+            <value> <string>erp5_sql_connection</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>z_related_project_uid_from_stock</string> </value>
+        </item>
+        <item>
+            <key> <string>max_cache_</string> </key>
+            <value> <int>100</int> </value>
+        </item>
+        <item>
+            <key> <string>max_rows_</string> </key>
+            <value> <int>1000</int> </value>
+        </item>
+        <item>
+            <key> <string>src</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.project_uid
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>template</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="__newobj__" module="copy_reg"/>
+                </klass>
+                <tuple>
+                  <global name="SQL" module="Shared.DC.ZRDB.DA"/>
+                </tuple>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>__name__</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<string>
+
+]]></string> </value>
+                    </item>
+                    <item>
+                        <key> <string>_vars</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>globals</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>raw</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.project_uid
+
+]]></string> </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.catalog_keys.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.catalog_keys.xml
new file mode 100644
index 0000000000..7d6996cb9c
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.catalog_keys.xml
@@ -0,0 +1,2 @@
+<catalog_method>
+</catalog_method>
\ No newline at end of file
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.xml
new file mode 100644
index 0000000000..cf70043ef2
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="SQL" module="Products.ZSQLMethods.SQL"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_arg</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="Args" module="Shared.DC.ZRDB.Aqueduct"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_data</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>table_0</string> </key>
+                                <value>
+                                  <dictionary/>
+                                </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>_keys</string> </key>
+                        <value>
+                          <list>
+                            <string>table_0</string>
+                          </list>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>allow_simple_one_argument_traversal</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>arguments_src</string> </key>
+            <value> <string>table_0</string> </value>
+        </item>
+        <item>
+            <key> <string>cache_time_</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+        <item>
+            <key> <string>class_file_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>class_name_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>connection_hook</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>connection_id</string> </key>
+            <value> <string>erp5_sql_connection</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>z_related_strict_membership_function_uid_from_stock</string> </value>
+        </item>
+        <item>
+            <key> <string>max_cache_</string> </key>
+            <value> <int>100</int> </value>
+        </item>
+        <item>
+            <key> <string>max_rows_</string> </key>
+            <value> <int>1000</int> </value>
+        </item>
+        <item>
+            <key> <string>src</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.function_uid AND\n
+<dtml-var table_0>.category_strict_membership = 1\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>template</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="__newobj__" module="copy_reg"/>
+                </klass>
+                <tuple>
+                  <global name="SQL" module="Shared.DC.ZRDB.DA"/>
+                </tuple>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>__name__</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<string>
+
+]]></string> </value>
+                    </item>
+                    <item>
+                        <key> <string>_vars</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>globals</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>raw</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.function_uid AND\n
+<dtml-var table_0>.category_strict_membership = 1\n
+
+
+]]></string> </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.catalog_keys.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.catalog_keys.xml
new file mode 100644
index 0000000000..7d6996cb9c
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.catalog_keys.xml
@@ -0,0 +1,2 @@
+<catalog_method>
+</catalog_method>
\ No newline at end of file
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.xml
new file mode 100644
index 0000000000..ee2b7354f5
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock.xml
@@ -0,0 +1,156 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <tuple>
+        <global name="SQL" module="Products.ZSQLMethods.SQL"/>
+        <tuple/>
+      </tuple>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>_arg</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="Args" module="Shared.DC.ZRDB.Aqueduct"/>
+                </klass>
+                <tuple/>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>_data</string> </key>
+                        <value>
+                          <dictionary>
+                            <item>
+                                <key> <string>table_0</string> </key>
+                                <value>
+                                  <dictionary/>
+                                </value>
+                            </item>
+                          </dictionary>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>_keys</string> </key>
+                        <value>
+                          <list>
+                            <string>table_0</string>
+                          </list>
+                        </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>allow_simple_one_argument_traversal</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>arguments_src</string> </key>
+            <value> <string>table_0</string> </value>
+        </item>
+        <item>
+            <key> <string>cache_time_</string> </key>
+            <value> <int>0</int> </value>
+        </item>
+        <item>
+            <key> <string>class_file_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>class_name_</string> </key>
+            <value> <string></string> </value>
+        </item>
+        <item>
+            <key> <string>connection_hook</string> </key>
+            <value>
+              <none/>
+            </value>
+        </item>
+        <item>
+            <key> <string>connection_id</string> </key>
+            <value> <string>erp5_sql_connection</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>z_related_strict_membership_project_uid_from_stock</string> </value>
+        </item>
+        <item>
+            <key> <string>max_cache_</string> </key>
+            <value> <int>100</int> </value>
+        </item>
+        <item>
+            <key> <string>max_rows_</string> </key>
+            <value> <int>1000</int> </value>
+        </item>
+        <item>
+            <key> <string>src</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.project_uid AND\n
+<dtml-var table_0>.category_strict_membership = 1\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>template</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="__newobj__" module="copy_reg"/>
+                </klass>
+                <tuple>
+                  <global name="SQL" module="Shared.DC.ZRDB.DA"/>
+                </tuple>
+                <state>
+                  <dictionary>
+                    <item>
+                        <key> <string>__name__</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<string>
+
+]]></string> </value>
+                    </item>
+                    <item>
+                        <key> <string>_vars</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>globals</string> </key>
+                        <value>
+                          <dictionary/>
+                        </value>
+                    </item>
+                    <item>
+                        <key> <string>raw</string> </key>
+                        <value> <string encoding="cdata"><![CDATA[
+
+<dtml-var table_0>.uid = stock.project_uid AND\n
+<dtml-var table_0>.category_strict_membership = 1\n
+
+
+]]></string> </value>
+                    </item>
+                  </dictionary>
+                </state>
+              </object>
+            </value>
+        </item>
+        <item>
+            <key> <string>title</string> </key>
+            <value> <string></string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogRelatedKeyTemplateItem/related_key_list.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogRelatedKeyTemplateItem/related_key_list.xml
index 5f5f8c8498..5850938dc6 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogRelatedKeyTemplateItem/related_key_list.xml
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogRelatedKeyTemplateItem/related_key_list.xml
@@ -24,12 +24,16 @@
  <key>parent_title | catalog/title/z_related_parent</key>
  <key>predicate_uid | predicate/uid/z_related_predicate</key>
  <key>resourceType | movement,catalog/portal_type/z_related_resource_from_movement</key>
+ <key>stock_function_category_strict_membership_uid | category/category_uid/z_related_strict_membership_function_uid_from_stock</key>
+ <key>stock_function_category_uid | category/category_uid/z_related_function_uid_from_stock</key>
  <key>stock_mirror_section_category_strict_membership_uid | category/category_uid/z_related_strict_membership_mirror_section_uid_from_stock</key>
  <key>stock_mirror_section_category_uid | category/category_uid/z_related_mirror_section_uid_from_stock</key>
  <key>stock_node_category_strict_membership_uid | category/category_uid/z_related_strict_membership_node_uid_from_stock</key>
  <key>stock_node_category_uid | category/category_uid/z_related_node_uid_from_stock</key>
  <key>stock_payment_category_strict_membership_uid | category/category_uid/z_related_strict_membership_payment_uid_from_stock</key>
  <key>stock_payment_category_uid | category/category_uid/z_related_payment_uid_from_stock</key>
+ <key>stock_project_category_strict_membership_uid | category/category_uid/z_related_strict_membership_project_uid_from_stock</key>
+ <key>stock_project_category_uid | category/category_uid/z_related_project_uid_from_stock</key>
  <key>stock_resource_category_strict_membership_uid | category/category_uid/z_related_strict_membership_resource_uid_from_stock</key>
  <key>stock_resource_category_uid | category/category_uid/z_related_resource_uid_from_stock</key>
  <key>stock_section_category_strict_membership_uid | category/category_uid/z_related_strict_membership_section_uid_from_stock</key>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision
index c2807f7f3c..83248fb9df 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision
@@ -1 +1 @@
-140
\ No newline at end of file
+142
\ No newline at end of file
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list
index 57ace64dfe..3acdcf89ef 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list
@@ -82,6 +82,7 @@ erp5_mysql_innodb/z_record_object_list
 erp5_mysql_innodb/z_related_base_category_id
 erp5_mysql_innodb/z_related_career_skill
 erp5_mysql_innodb/z_related_explanation
+erp5_mysql_innodb/z_related_function_uid_from_stock
 erp5_mysql_innodb/z_related_grand_parent
 erp5_mysql_innodb/z_related_metric_type
 erp5_mysql_innodb/z_related_mirror_section_uid_from_stock
@@ -91,13 +92,16 @@ erp5_mysql_innodb/z_related_parent_specialise
 erp5_mysql_innodb/z_related_parent_strict_group
 erp5_mysql_innodb/z_related_payment_uid_from_stock
 erp5_mysql_innodb/z_related_predicate
+erp5_mysql_innodb/z_related_project_uid_from_stock
 erp5_mysql_innodb/z_related_resource_from_movement
 erp5_mysql_innodb/z_related_resource_uid_from_stock
 erp5_mysql_innodb/z_related_section_uid_from_stock
 erp5_mysql_innodb/z_related_security
+erp5_mysql_innodb/z_related_strict_membership_function_uid_from_stock
 erp5_mysql_innodb/z_related_strict_membership_mirror_section_uid_from_stock
 erp5_mysql_innodb/z_related_strict_membership_node_uid_from_stock
 erp5_mysql_innodb/z_related_strict_membership_payment_uid_from_stock
+erp5_mysql_innodb/z_related_strict_membership_project_uid_from_stock
 erp5_mysql_innodb/z_related_strict_membership_resource_uid_from_stock
 erp5_mysql_innodb/z_related_strict_membership_section_uid_from_stock
 erp5_mysql_innodb/z_related_translated_causality_state
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_related_key_list b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_related_key_list
index 2ae99d39bb..6162d1daeb 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_related_key_list
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_related_key_list
@@ -26,6 +26,10 @@ base_category_id | category,catalog/id/z_related_base_category_id
 grand_parent_simulation_state | catalog,catalog/simulation_state/z_related_grand_parent
 stock_mirror_section_category_uid | category/category_uid/z_related_mirror_section_uid_from_stock
 stock_node_category_strict_membership_uid | category/category_uid/z_related_strict_membership_node_uid_from_stock
+stock_function_category_strict_membership_uid | category/category_uid/z_related_strict_membership_function_uid_from_stock
+stock_function_category_uid | category/category_uid/z_related_function_uid_from_stock
+stock_project_category_strict_membership_uid | category/category_uid/z_related_strict_membership_project_uid_from_stock
+stock_project_category_uid | category/category_uid/z_related_project_uid_from_stock
 deliveryLineType | movement,catalog/portal_type/z_related_uid_or_parent_uid
 item_section_category_uid | category/category_uid/z_related_section_uid_from_item
 parent_specialise_portal_type | category,catalog/portal_type/z_related_parent_specialise
diff --git a/product/ERP5/tests/testInventoryAPI.py b/product/ERP5/tests/testInventoryAPI.py
index 5859ee7ce7..2220a45571 100644
--- a/product/ERP5/tests/testInventoryAPI.py
+++ b/product/ERP5/tests/testInventoryAPI.py
@@ -189,6 +189,8 @@ class InventoryAPITestCase(ERP5TypeTestCase):
               'group/level1/level2',
               'group/anotherlevel',
               'product_line/level1/level2',
+              'function/function1',
+              'function/function1/function2',
            # we create a huge group category for consolidation tests
            ) + self.GROUP_CATEGORIES + self.VARIATION_CATEGORIES
   
@@ -393,6 +395,90 @@ class TestInventory(InventoryAPITestCase):
     self.assertEquals(getInventory(
                 node_category_strict_membership=['group/level1']), 100)
   
+  def test_Function(self):
+    """Tests inventory on function"""
+    getInventory = self.getSimulationTool().getInventory
+    self._makeMovement(quantity=100,
+                       destination_function='function/function1')
+    self.assertEquals(getInventory(
+                        function='function/function1'), 100)
+    self.assertEquals(getInventory(
+                        function='function/function1/function2'), 0)
+
+  def test_FunctionUid(self):
+    """Tests inventory on function uid"""
+    getInventory = self.getSimulationTool().getInventory
+    function = self.portal.portal_categories.function
+    self._makeMovement(quantity=100,
+                       destination_function='function/function1')
+    self.assertEquals(getInventory(
+                        function_uid=function.function1.getUid()), 100)
+    self.assertEquals(getInventory(
+                        function_uid=function.function1.function2.getUid()), 0)
+
+  def test_FunctionCategory(self):
+    """Tests inventory on function category"""
+    getInventory = self.getSimulationTool().getInventory
+    function = self.portal.portal_categories.function
+    self._makeMovement(quantity=100,
+                       destination_function='function/function1/function2')
+    self.assertEquals(getInventory(
+                        function_category='function/function1'), 100)
+    self.assertEquals(getInventory(
+                        function='function/function1/function2'), 100)
+
+  def test_FunctionCategoryStrictMembership(self):
+    """Tests inventory on function category strict membership"""
+    getInventory = self.getSimulationTool().getInventory
+    function = self.portal.portal_categories.function
+    self._makeMovement(quantity=100,
+                       destination_function='function/function1/function2')
+    self.assertEquals(getInventory(
+            function_category_strict_membership='function/function1'), 0)
+    self.assertEquals(getInventory(
+            function_category_strict_membership='function/function1/function2'), 100)
+  
+  def test_Project(self):
+    """Tests inventory on project"""
+    getInventory = self.getSimulationTool().getInventory
+    self._makeMovement(quantity=100,
+                       destination_project_value=self.mirror_node)
+    self.assertEquals(getInventory(
+                        project=self.mirror_node.getRelativeUrl()), 100)
+
+  def test_ProjectUid(self):
+    """Tests inventory on project uid"""
+    getInventory = self.getSimulationTool().getInventory
+    self._makeMovement(quantity=100,
+                       destination_project_value=self.mirror_node)
+    self.assertEquals(getInventory(
+                        project_uid=self.mirror_node.getUid()), 100)
+
+  def test_ProjectCategory(self):
+    """Tests inventory on project category"""
+    # this test uses unrealistic data
+    getInventory = self.getSimulationTool().getInventory
+    self.mirror_node.setGroup('level1/level2')
+    self._makeMovement(quantity=100,
+                       destination_project_value=self.mirror_node)
+    self.assertEquals(getInventory(
+                        project_category='group/level1'), 100)
+    self.assertEquals(getInventory(
+                        project_category='group/level1/level2'), 100)
+
+  def test_ProjectCategoryStrictMembership(self):
+    """Tests inventory on project category strict membership"""
+    # this test uses unrealistic data
+    getInventory = self.getSimulationTool().getInventory
+    self.mirror_node.setGroup('level1/level2')
+    self._makeMovement(quantity=100,
+                       destination_project_value=self.mirror_node)
+    self.assertEquals(getInventory(
+                project_category_strict_membership='group/level1'), 0)
+    self.assertEquals(getInventory(
+                project_category_strict_membership='group/level1/level2'), 100)
+
+
   def test_ResourceCategory(self):
     """Tests inventory on resource_category """
     getInventory = self.getSimulationTool().getInventory
-- 
2.30.9