From 23f94525ce4ec5c01401b498af4a97d726161dbc Mon Sep 17 00:00:00 2001
From: Kazuhiko Shiozaki <kazuhiko@nexedi.com>
Date: Wed, 28 Feb 2007 07:57:34 +0000
Subject: [PATCH] * add
 SelectionTool.buildSQLJoinExpressionFromDomainSelection() * add
 SelectionTool.buildSQLExpressionFromDomainSelection() * please use these
 methods instead of selection_domain.asSQLJoinExpression   and
 selection_domain.asSQLExpression. * to pass a DomainSelection instance to
 these methods is   deprecated. please use a domain dict instance to these
 methods   instead.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@13092 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/CMFCategory/CategoryTool.py           |  6 ++--
 .../erp5_core/Resource_zGetInventory.xml      | 18 +++++------
 .../erp5_core/Resource_zGetInventoryList.xml  | 18 +++++------
 .../Resource_zGetMovementHistoryList.xml      | 18 +++++------
 .../erp5_core/Resource_zGetTrackingList.xml   | 18 +++++------
 .../erp5_core/Resource_zStatInventory.xml     | 16 +++++-----
 .../erp5_mysql_innodb/z_count_results.xml     | 16 +++++-----
 .../erp5_mysql_innodb/z_search_results.xml    | 16 +++++-----
 .../erp5_mysql_ndb/z_count_results.xml        | 16 +++++-----
 .../erp5_mysql_ndb/z_search_results.xml       | 16 +++++-----
 product/ERP5Form/SelectionTool.py             | 32 +++++++++++++++++++
 11 files changed, 106 insertions(+), 84 deletions(-)

diff --git a/product/CMFCategory/CategoryTool.py b/product/CMFCategory/CategoryTool.py
index f63015b57e..50e34e28a2 100644
--- a/product/CMFCategory/CategoryTool.py
+++ b/product/CMFCategory/CategoryTool.py
@@ -1381,7 +1381,6 @@ class CategoryTool( UniqueObject, Folder, Base ):
       """
       This returns a catalog_search resource with can then be used by getCategoryMemberItemList
       """
-      from Products.ERP5Form.Selection import DomainSelection
       if base_category is None:
         if context.getPortalType() in ( "Base Category", "Category") :
           base_category = context.getBaseCategoryId()
@@ -1390,13 +1389,12 @@ class CategoryTool( UniqueObject, Folder, Base ):
       strict_membership = kw.get('strict_membership', kw.get('strict', 0))
 
       domain_dict = {base_category: ('portal_categories', context.getRelativeUrl())}
-      selection_domain = DomainSelection(domain_dict = domain_dict).__of__(context)
       if strict_membership:
         catalog_search = self.portal_catalog(portal_type = portal_type,
-		           selection_report = selection_domain)
+                           selection_report = domain_dict)
       else:
         catalog_search = self.portal_catalog(portal_type = portal_type,
-                           selection_domain = selection_domain)
+                           selection_domain = domain_dict)
 
       return catalog_search
 
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventory.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventory.xml
index 22365e6dd8..0e4b902d1c 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventory.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventory.xml
@@ -260,9 +260,9 @@ FROM\n
   </dtml-if>\n
 </dtml-in>\n
   <dtml-if selection_domain>,\n
-    <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
+    <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
   <dtml-if selection_report>,\n
-    <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+    <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
   , catalog as node, catalog as resource\n
 \n
 WHERE\n
@@ -313,11 +313,10 @@ WHERE\n
 </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'stock\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'stock\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 \n
 <dtml-if group_by_expression>\n
@@ -397,9 +396,9 @@ FROM\n
   </dtml-if>\n
 </dtml-in>\n
   <dtml-if selection_domain>,\n
-    <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
+    <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
   <dtml-if selection_report>,\n
-    <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+    <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
   , catalog as node, catalog as resource\n
 \n
 WHERE\n
@@ -450,11 +449,10 @@ WHERE\n
 </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'stock\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'stock\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 \n
 <dtml-if group_by_expression>\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml
index 0d957f1939..e5d593912b 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetInventoryList.xml
@@ -257,8 +257,8 @@ FROM\n
   , <dtml-var table_item> AS <dtml-var table_key>\n
   </dtml-if>\n
 </dtml-in>\n
-  <dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-  <dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+  <dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+  <dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
   , catalog as node, catalog as resource\n
 \n
 WHERE\n
@@ -314,11 +314,10 @@ WHERE\n
 </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'stock\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'stock\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 GROUP BY\n
   <dtml-if group_by_expression>\n
@@ -398,8 +397,8 @@ FROM\n
   , <dtml-var table_item> AS <dtml-var table_key>\n
   </dtml-if>\n
 </dtml-in>\n
-  <dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-  <dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+  <dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+  <dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
   , catalog as node, catalog as resource\n
 \n
 WHERE\n
@@ -455,11 +454,10 @@ WHERE\n
 </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'stock\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'stock\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 GROUP BY\n
   <dtml-if group_by_expression>\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetMovementHistoryList.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetMovementHistoryList.xml
index fd0b6fb9e5..1a55ba2aa9 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetMovementHistoryList.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetMovementHistoryList.xml
@@ -695,8 +695,8 @@ FROM\n
   , <dtml-var table_item> AS <dtml-var table_key>\n
   </dtml-if>\n
 </dtml-in>\n
-  <dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-  <dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+  <dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+  <dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
   , catalog as node, catalog as resource\n
 \n
 WHERE\n
@@ -752,11 +752,10 @@ WHERE\n
 </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'stock\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'stock\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 \n
 GROUP BY\n
@@ -852,8 +851,8 @@ FROM\n
   , <dtml-var table_item> AS <dtml-var table_key>\n
   </dtml-if>\n
 </dtml-in>\n
-  <dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-  <dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+  <dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+  <dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
   , catalog as node, catalog as resource\n
 \n
 WHERE\n
@@ -909,11 +908,10 @@ WHERE\n
 </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'stock\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'stock\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 \n
 GROUP BY\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetTrackingList.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetTrackingList.xml
index c75adb2aa7..06abd6ab9f 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetTrackingList.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zGetTrackingList.xml
@@ -407,8 +407,8 @@ FROM\n
     <dtml-if expr="table_key != \'item\'">, <dtml-var table_item> AS <dtml-var table_key></dtml-if>\n
   </dtml-in>\n
 </dtml-if>\n
-<dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-<dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+<dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+<dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
 , item\n
 \n
 \n
@@ -456,11 +456,10 @@ WHERE\n
 \n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'item\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'item\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 \n
 <dtml-if group_by_expression>\n
@@ -526,8 +525,8 @@ FROM\n
     <dtml-if expr="table_key != \'item\'">, <dtml-var table_item> AS <dtml-var table_key></dtml-if>\n
   </dtml-in>\n
 </dtml-if>\n
-<dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-<dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+<dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+<dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
 , item\n
 \n
 \n
@@ -575,11 +574,10 @@ WHERE\n
 \n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression(join_table=\'item\',\n
-                                                  join_column=\'node_uid\')">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=\'item\', join_column=\'node_uid\')">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression(strict_membership=1)">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
 </dtml-if>\n
 \n
 <dtml-if group_by_expression>\n
diff --git a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zStatInventory.xml b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zStatInventory.xml
index 118f89017b..8772a38724 100644
--- a/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zStatInventory.xml
+++ b/product/ERP5/bootstrap/erp5_core/SkinTemplateItem/portal_skins/erp5_core/Resource_zStatInventory.xml
@@ -271,8 +271,8 @@ FROM\n
      , <dtml-var sequence-item> AS <dtml-var sequence-key>\n
      </dtml-in>\n
   </dtml-if>\n
-  <dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-  <dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+  <dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+  <dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
 \n
 WHERE\n
   child.uid = stock.uid\n
@@ -337,10 +337,10 @@ WHERE\n
   </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression()">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression()">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report)">\n
 </dtml-if>\n
 <dtml-if selection_uids>\n
   AND\n
@@ -414,8 +414,8 @@ FROM\n
      , <dtml-var sequence-item> AS <dtml-var sequence-key>\n
      </dtml-in>\n
   </dtml-if>\n
-  <dtml-if selection_domain>, <dtml-var "selection_domain.asSQLJoinExpression()"> </dtml-if>\n
-  <dtml-if selection_report>, <dtml-var "selection_report.asSQLJoinExpression()"> </dtml-if>\n
+  <dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if>\n
+  <dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>\n
 \n
 WHERE\n
   child.uid = stock.uid\n
@@ -480,10 +480,10 @@ WHERE\n
   </dtml-if>\n
 \n
 <dtml-if selection_domain>\n
-  AND <dtml-var "selection_domain.asSQLExpression()">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  AND <dtml-var "selection_report.asSQLExpression()">\n
+  AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report)">\n
 </dtml-if>\n
 <dtml-if selection_uids>\n
   AND\n
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_count_results.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_count_results.xml
index b2ddeeb89a..fb45d2b629 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_count_results.xml
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_count_results.xml
@@ -150,12 +150,12 @@ SELECT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression(category_table_alias = \'domain_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression(category_table_alias = \'report_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias = \'report_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -165,12 +165,12 @@ WHERE\n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression(category_table_alias = \'domain_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1, category_table_alias = \'report_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1, category_table_alias = \'report_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
@@ -228,12 +228,12 @@ SELECT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression(category_table_alias = \'domain_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression(category_table_alias = \'report_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias = \'report_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -243,12 +243,12 @@ WHERE\n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression(category_table_alias = \'domain_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1, category_table_alias = \'report_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1, category_table_alias = \'report_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_search_results.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_search_results.xml
index 1fc7b397dc..af14ad6047 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_search_results.xml
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/z_search_results.xml
@@ -186,12 +186,12 @@ SELECT DISTINCT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression(category_table_alias = \'domain_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression(category_table_alias = \'report_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias = \'report_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -202,12 +202,12 @@ WHERE \n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression(category_table_alias = \'domain_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1, category_table_alias = \'report_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1, category_table_alias = \'report_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
@@ -267,12 +267,12 @@ SELECT DISTINCT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression(category_table_alias = \'domain_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression(category_table_alias = \'report_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias = \'report_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -283,12 +283,12 @@ WHERE \n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression(category_table_alias = \'domain_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1, category_table_alias = \'report_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1, category_table_alias = \'report_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
diff --git a/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_count_results.xml b/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_count_results.xml
index b31a346dbc..7ce91860d7 100644
--- a/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_count_results.xml
+++ b/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_count_results.xml
@@ -142,12 +142,12 @@ SELECT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression(category_table_alias = \'domain_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression(category_table_alias = \'report_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias = \'report_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -157,12 +157,12 @@ WHERE\n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression(category_table_alias = \'domain_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1, category_table_alias = \'report_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1, category_table_alias = \'report_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
@@ -220,12 +220,12 @@ SELECT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression()">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression()">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -235,12 +235,12 @@ WHERE\n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression()">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1)">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
diff --git a/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_search_results.xml b/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_search_results.xml
index 9a11e900c0..c65ec68317 100644
--- a/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_search_results.xml
+++ b/product/ERP5/bootstrap/erp5_mysql_ndb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_ndb/z_search_results.xml
@@ -178,12 +178,12 @@ SELECT DISTINCT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression(category_table_alias = \'domain_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression(category_table_alias = \'report_category\')">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias = \'report_category\')">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -194,12 +194,12 @@ WHERE \n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression(category_table_alias = \'domain_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias = \'domain_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1, category_table_alias = \'report_category\')">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1, category_table_alias = \'report_category\')">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
@@ -259,12 +259,12 @@ SELECT DISTINCT\n
 FROM\n
   <dtml-in from_table_list> <dtml-var sequence-item> AS <dtml-var sequence-key><dtml-if sequence-end><dtml-else>,</dtml-if></dtml-in>\n
   <dtml-if selection_domain>\n
-    <dtml-let expression="selection_domain.asSQLJoinExpression()">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
   <dtml-if selection_report>\n
-    <dtml-let expression="selection_report.asSQLJoinExpression()">\n
+    <dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)">\n
       <dtml-if expression> , <dtml-var expression> </dtml-if>\n
     </dtml-let>\n
   </dtml-if>\n
@@ -275,12 +275,12 @@ WHERE \n
   AND <dtml-var where_expression>\n
 </dtml-if>\n
 <dtml-if selection_domain>\n
-  <dtml-let expression="selection_domain.asSQLExpression()">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_domain)">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
 <dtml-if selection_report>\n
-  <dtml-let expression="selection_report.asSQLExpression(strict_membership=1)">\n
+  <dtml-let expression="portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">\n
     <dtml-if expression> AND <dtml-var expression> </dtml-if>\n
   </dtml-let>\n
 </dtml-if>\n
diff --git a/product/ERP5Form/SelectionTool.py b/product/ERP5Form/SelectionTool.py
index 3bc55212d2..2e7224fc27 100644
--- a/product/ERP5Form/SelectionTool.py
+++ b/product/ERP5Form/SelectionTool.py
@@ -53,6 +53,7 @@ import string
 from zLOG import LOG
 from Acquisition import Implicit, aq_base
 from Products.ERP5Type.Message import Message
+import warnings
 
 class SelectionError( Exception ):
     pass
@@ -1156,6 +1157,37 @@ class SelectionTool( UniqueObject, SimpleItem ):
         # Return the search dialog
         return getattr(o, dialog_id)(REQUEST=REQUEST)
 
+    security.declarePublic('buildSQLJoinExpressionFromDomainSelection')
+    def buildSQLJoinExpressionFromDomainSelection(self, selection_domain,
+                                                  domain_id=None,
+                                                  exclude_domain_id=None,
+                                                  category_table_alias='category'):
+      if isinstance(selection_domain, DomainSelection):
+        warnings.warn("To pass a DomainSelection instance is deprecated.\n"
+                      "Please use a domain dict instead.",
+                      DeprecationWarning)
+      else:
+        selection_domain = DomainSelection(selection_domain).__of__(self)
+      return selection_domain.asSQLJoinExpression(category_table_alias = category_table_alias)
+
+    security.declarePublic('buildSQLExpressionFromDomainSelection')
+    def buildSQLExpressionFromDomainSelection(self, selection_domain,
+                                              table_map=None, domain_id=None, 
+                                              exclude_domain_id=None,
+                                              strict_membership=0,
+                                              join_table="catalog",
+                                              join_column="uid",
+                                              base_category=None,
+                                              category_table_alias='category'):
+      if isinstance(selection_domain, DomainSelection):
+        warnings.warn("To pass a DomainSelection instance is deprecated.\n"
+                      "Please use a domain dict instead.",
+                      DeprecationWarning)
+      else:
+        selection_domain = DomainSelection(selection_domain).__of__(self)
+      return selection_domain.asSQLExpression(strict_membership = strict_membership,
+                                              category_table_alias = category_table_alias)
+
     def _aq_dynamic(self, name):
       """
         Generate viewSearchRelatedDocumentDialog0,
-- 
2.30.9