Commit b7e644e4 authored by Vincent Pelletier's avatar Vincent Pelletier

SimulationTool: Stop relying on portal_selections for SQL expression generation

parent 958c3b87
...@@ -76,12 +76,11 @@ FROM ...@@ -76,12 +76,11 @@ FROM
AND quantity_unit_conversion.quantity_unit_uid = <dtml-sqlvar quantity_unit_uid type=int>) AND quantity_unit_conversion.quantity_unit_uid = <dtml-sqlvar quantity_unit_uid type=int>)
</dtml-if> </dtml-if>
<dtml-in prefix="table" expr="from_table_list"> <dtml-in prefix="table" expr="from_table_list">
<dtml-if expr="table_key not in ('catalog', stock_table_id)"> <dtml-if expr="table_key not in ('catalog', 'node', stock_table_id)">
, <dtml-var table_item> AS <dtml-var table_key> , <dtml-var table_item> AS <dtml-var table_key>
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
<dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if> <dtml-if "selection_domain_from_expression">, <dtml-var "selection_domain_from_expression"> </dtml-if>
<dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>
, catalog as node, catalog as resource <dtml-if transformed_uid>, transformation, catalog as transformed_resource</dtml-if> , catalog as node, catalog as resource <dtml-if transformed_uid>, transformation, catalog as transformed_resource</dtml-if>
WHERE WHERE
...@@ -110,11 +109,8 @@ WHERE ...@@ -110,11 +109,8 @@ WHERE
AND catalog.portal_type != 'Simulation Movement' AND catalog.portal_type != 'Simulation Movement'
</dtml-if> </dtml-if>
<dtml-if selection_domain> <dtml-if "selection_domain_where_expression">
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table=stock_table_id, join_column='node_uid')"> AND <dtml-var "selection_domain_where_expression">
</dtml-if>
<dtml-if selection_report>
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">
</dtml-if> </dtml-if>
<dtml-if convert_quantity_result> <dtml-if convert_quantity_result>
......
...@@ -26,9 +26,9 @@ ...@@ -26,9 +26,9 @@
where_expression\r\n where_expression\r\n
order_by_expression\r\n order_by_expression\r\n
group_by_expression\r\n group_by_expression\r\n
selection_domain\r\n selection_domain_from_expression\r\n
selection_domain_where_expression\r\n
select_expression\r\n select_expression\r\n
selection_report\r\n
ignore_variation\r\n ignore_variation\r\n
standardize\r\n standardize\r\n
omit_simulation\r\n omit_simulation\r\n
......
...@@ -504,7 +504,17 @@ class SimulationTool(BaseTool): ...@@ -504,7 +504,17 @@ class SimulationTool(BaseTool):
# catalog # catalog
new_kw.pop('ignore_group_by', None) new_kw.pop('ignore_group_by', None)
sql_kw.update(ctool.buildSQLQuery(**new_kw)) catalog_sql_kw = ctool.buildSQLQuery(**new_kw)
from_table_dict = dict(sql_kw.pop('from_table_list', []))
for alias, table in catalog_sql_kw.pop('from_table_list', None) or []:
assert from_table_dict.get(alias) in (None, table), (
alias,
table,
from_table_dict[alias],
)
from_table_dict[alias] = table
sql_kw.update(catalog_sql_kw)
sql_kw['from_table_list'] = from_table_dict.items()
return sql_kw return sql_kw
def _generateKeywordDict(self, def _generateKeywordDict(self,
...@@ -592,6 +602,9 @@ class SimulationTool(BaseTool): ...@@ -592,6 +602,9 @@ class SimulationTool(BaseTool):
# sort_on # sort_on
sort_on=None, sort_on=None,
group_by=None, group_by=None,
# selection
selection_domain=None,
selection_report=None,
# keywords for related keys # keywords for related keys
**kw): **kw):
""" """
...@@ -601,11 +614,36 @@ class SimulationTool(BaseTool): ...@@ -601,11 +614,36 @@ class SimulationTool(BaseTool):
column. If 0, it also used the mirror_date column. column. If 0, it also used the mirror_date column.
""" """
new_kw = {} new_kw = {}
sql_kw = {} sql_kw = {
'from_table_list': [],
# Set of catalog aliases that must be joined in the ZSQLMethod ('foo'
# meaning something along the lines of 'foo.uid = stock.foo_uid')
'selection_domain_catalog_alias_set': [],
# input and output are used by getTrackingList # input and output are used by getTrackingList
sql_kw['input'] = input 'input': input,
sql_kw['output'] = output 'output': output,
# BBB
'selection_domain': None,
'selection_report': None,
}
if selection_domain is None:
sql_kw['selection_domain_from_expression'] = None
sql_kw['selection_domain_where_expression'] = None
else:
# Pre-render selection_domain, as it is easier done here than in DTML.
query_table_alias = 'node' # XXX: To be eventually made configurable
selection_domain_sql_dict = self.getPortalObject().portal_catalog.buildSQLQuery(
selection_domain=selection_domain,
query_table_alias=query_table_alias,
)
sql_kw['selection_domain_from_expression'] = selection_domain_sql_dict['from_expression']
sql_kw['from_table_list'].extend(selection_domain_sql_dict['from_table_list'])
sql_kw['selection_domain_where_expression'] = selection_domain_sql_dict['where_expression']
sql_kw['selection_domain_catalog_alias_set'].append(query_table_alias)
if selection_report is not None:
new_kw['selection_report'] = selection_report
# Add sort_on parameter if defined # Add sort_on parameter if defined
if sort_on is not None: if sort_on is not None:
new_kw['sort_on'] = sort_on new_kw['sort_on'] = sort_on
...@@ -1178,7 +1216,6 @@ class SimulationTool(BaseTool): ...@@ -1178,7 +1216,6 @@ class SimulationTool(BaseTool):
omit_simulation=0, omit_simulation=0,
only_accountable=True, only_accountable=True,
default_stock_table='stock', default_stock_table='stock',
selection_domain=None, selection_report=None,
statistic=0, inventory_list=1, statistic=0, inventory_list=1,
precision=None, connection_id=None, precision=None, connection_id=None,
**kw): **kw):
...@@ -1259,8 +1296,6 @@ class SimulationTool(BaseTool): ...@@ -1259,8 +1296,6 @@ class SimulationTool(BaseTool):
'standardise': standardise, 'standardise': standardise,
'omit_simulation': omit_simulation, 'omit_simulation': omit_simulation,
'only_accountable': only_accountable, 'only_accountable': only_accountable,
'selection_domain': selection_domain,
'selection_report': selection_report,
'precision': precision, 'precision': precision,
'inventory_list': inventory_list, 'inventory_list': inventory_list,
'connection_id': connection_id, 'connection_id': connection_id,
...@@ -1883,8 +1918,7 @@ class SimulationTool(BaseTool): ...@@ -1883,8 +1918,7 @@ class SimulationTool(BaseTool):
def getInventoryHistoryList(self, src__=0, ignore_variation=0, def getInventoryHistoryList(self, src__=0, ignore_variation=0,
standardise=0, omit_simulation=0, standardise=0, omit_simulation=0,
only_accountable=True, omit_input=0, only_accountable=True, omit_input=0,
omit_output=0, selection_domain=None, omit_output=0, precision=None, **kw):
selection_report=None, precision=None, **kw):
""" """
Returns a time based serie of inventory values Returns a time based serie of inventory values
for a single or a group of resource, node, section, etc. This is useful for a single or a group of resource, node, section, etc. This is useful
...@@ -1900,8 +1934,7 @@ class SimulationTool(BaseTool): ...@@ -1900,8 +1934,7 @@ class SimulationTool(BaseTool):
standardise=standardise, omit_simulation=omit_simulation, standardise=standardise, omit_simulation=omit_simulation,
only_accountable=only_accountable, only_accountable=only_accountable,
omit_input=omit_input, omit_output=omit_output, omit_input=omit_input, omit_output=omit_output,
selection_domain=selection_domain, precision=precision,
selection_report=selection_report, precision=precision,
**sql_kw) **sql_kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -1910,8 +1943,7 @@ class SimulationTool(BaseTool): ...@@ -1910,8 +1943,7 @@ class SimulationTool(BaseTool):
standardise=0, omit_simulation=0, standardise=0, omit_simulation=0,
only_accountable=True, only_accountable=True,
omit_input=0, omit_output=0, omit_input=0, omit_output=0,
selection_domain=None, precision=None, **kw):
selection_report=None, precision=None, **kw):
""" """
getInventoryHistoryChart is the pensing to getInventoryHistoryList getInventoryHistoryChart is the pensing to getInventoryHistoryList
to ease the rendering of time based graphs which show the evolution to ease the rendering of time based graphs which show the evolution
...@@ -1926,8 +1958,7 @@ class SimulationTool(BaseTool): ...@@ -1926,8 +1958,7 @@ class SimulationTool(BaseTool):
standardise=standardise, omit_simulation=omit_simulation, standardise=standardise, omit_simulation=omit_simulation,
only_accountable=only_accountable, only_accountable=only_accountable,
omit_input=omit_input, omit_output=omit_output, omit_input=omit_input, omit_output=omit_output,
selection_domain=selection_domain, precision=precision,
selection_report=selection_report, precision=precision,
**sql_kw) **sql_kw)
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -1937,7 +1968,6 @@ class SimulationTool(BaseTool): ...@@ -1937,7 +1968,6 @@ class SimulationTool(BaseTool):
omit_input=0, omit_output=0, omit_input=0, omit_output=0,
only_accountable=True, only_accountable=True,
omit_asset_increase=0, omit_asset_decrease=0, omit_asset_increase=0, omit_asset_decrease=0,
selection_domain=None, selection_report=None,
initial_running_total_quantity=0, initial_running_total_quantity=0,
initial_running_total_price=0, precision=None, initial_running_total_price=0, precision=None,
**kw): **kw):
...@@ -1965,8 +1995,6 @@ class SimulationTool(BaseTool): ...@@ -1965,8 +1995,6 @@ class SimulationTool(BaseTool):
omit_input=omit_input, omit_output=omit_output, omit_input=omit_input, omit_output=omit_output,
omit_asset_increase=omit_asset_increase, omit_asset_increase=omit_asset_increase,
omit_asset_decrease=omit_asset_decrease, omit_asset_decrease=omit_asset_decrease,
selection_domain=selection_domain,
selection_report=selection_report,
initial_running_total_quantity= initial_running_total_quantity=
initial_running_total_quantity, initial_running_total_quantity,
initial_running_total_price= initial_running_total_price=
...@@ -2065,7 +2093,6 @@ class SimulationTool(BaseTool): ...@@ -2065,7 +2093,6 @@ class SimulationTool(BaseTool):
# Traceability management # Traceability management
security.declareProtected(Permissions.AccessContentsInformation, 'getTrackingList') security.declareProtected(Permissions.AccessContentsInformation, 'getTrackingList')
def getTrackingList(self, src__=0, def getTrackingList(self, src__=0,
selection_domain=None, selection_report=None,
strict_simulation_state=1, history=0, **kw) : strict_simulation_state=1, history=0, **kw) :
""" """
Returns a list of items in the form Returns a list of items in the form
...@@ -2171,8 +2198,6 @@ class SimulationTool(BaseTool): ...@@ -2171,8 +2198,6 @@ class SimulationTool(BaseTool):
new_kw['simulation_state_list'] = None new_kw['simulation_state_list'] = None
return self.Resource_zGetTrackingList(src__=src__, return self.Resource_zGetTrackingList(src__=src__,
selection_domain=selection_domain,
selection_report=selection_report,
**new_kw) **new_kw)
security.declareProtected(Permissions.AccessContentsInformation, 'getCurrentTrackingList') security.declareProtected(Permissions.AccessContentsInformation, 'getCurrentTrackingList')
......
...@@ -75,8 +75,8 @@ FROM ...@@ -75,8 +75,8 @@ FROM
(quantity_unit_conversion.resource_uid = <dtml-var stock_table_id>.resource_uid (quantity_unit_conversion.resource_uid = <dtml-var stock_table_id>.resource_uid
AND quantity_unit_conversion.quantity_unit_uid = <dtml-sqlvar quantity_unit_uid type=int>) AND quantity_unit_conversion.quantity_unit_uid = <dtml-sqlvar quantity_unit_uid type=int>)
</dtml-if> </dtml-if>
<dtml-if selection_domain><dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias='domain_category')"><dtml-if expression>, <dtml-var expression></dtml-if></dtml-let></dtml-if> <dtml-if "selection_domain_from_expression">, <dtml-var "selection_domain_from_expression"> </dtml-if>
<dtml-if selection_report><dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias='report_category')"><dtml-if expression>, <dtml-var expression></dtml-if></dtml-let></dtml-if>
<dtml-if transformed_uid>, transformation, catalog as transformed_resource</dtml-if> <dtml-if transformed_uid>, transformation, catalog as transformed_resource</dtml-if>
WHERE WHERE
...@@ -102,11 +102,11 @@ WHERE ...@@ -102,11 +102,11 @@ WHERE
<dtml-if only_accountable> <dtml-if only_accountable>
AND <dtml-var stock_table_id>.is_accountable AND <dtml-var stock_table_id>.is_accountable
</dtml-if> </dtml-if>
<dtml-if selection_domain> <dtml-if "selection_domain_where_expression">
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias='domain_category', join_table=stock_table_id, join_column='node_uid')"> <dtml-in selection_domain_catalog_alias_set>
</dtml-if> AND <dtml-var stock_table_id>.<dtml-var sequence-item>_uid = <dtml-var sequence-item>.uid
<dtml-if selection_report> </dtml-in>
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, category_table_alias='report_category', strict_membership=1)"> AND <dtml-var "selection_domain_where_expression">
</dtml-if> </dtml-if>
<dtml-if convert_quantity_result> <dtml-if convert_quantity_result>
......
...@@ -27,9 +27,10 @@ from_expression\r\n ...@@ -27,9 +27,10 @@ from_expression\r\n
where_expression\r\n where_expression\r\n
order_by_expression\r\n order_by_expression\r\n
group_by_expression\r\n group_by_expression\r\n
selection_domain\r\n selection_domain_from_expression\r\n
selection_domain_where_expression\r\n
selection_domain_catalog_alias_set\r\n
select_expression\r\n select_expression\r\n
selection_report\r\n
ignore_variation\r\n ignore_variation\r\n
standardize\r\n standardize\r\n
omit_simulation\r\n omit_simulation\r\n
......
...@@ -55,8 +55,7 @@ FROM ...@@ -55,8 +55,7 @@ FROM
</dtml-if> </dtml-if>
</dtml-in> </dtml-in>
</dtml-if> </dtml-if>
<dtml-if selection_domain><dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain, category_table_alias='domain_category')"><dtml-if expression>, <dtml-var expression></dtml-if></dtml-let></dtml-if> <dtml-if "selection_domain_from_expression">, <dtml-var "selection_domain_from_expression"> </dtml-if>
<dtml-if selection_report><dtml-let expression="portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report, category_table_alias='report_category')"><dtml-if expression>, <dtml-var expression></dtml-if></dtml-let></dtml-if>
WHERE WHERE
stock.uid = catalog.uid stock.uid = catalog.uid
...@@ -132,11 +131,11 @@ WHERE ...@@ -132,11 +131,11 @@ WHERE
<dtml-unless sequence-end> OR </dtml-unless></dtml-in>) <dtml-unless sequence-end> OR </dtml-unless></dtml-in>)
</dtml-if> </dtml-if>
<dtml-if selection_domain> <dtml-if "selection_domain_where_expression">
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, category_table_alias='domain_category', join_table='stock', join_column='node_uid')"> <dtml-in selection_domain_catalog_alias_set>
</dtml-if> AND stock.<dtml-var sequence-item>_uid = <dtml-var sequence-item>.uid
<dtml-if selection_report> </dtml-in>
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, category_table_alias='report_category', strict_membership=1)"> AND <dtml-var "selection_domain_where_expression">
</dtml-if> </dtml-if>
<dtml-if group_by_expression> <dtml-if group_by_expression>
......
...@@ -424,8 +424,9 @@ where_expression\r\n ...@@ -424,8 +424,9 @@ where_expression\r\n
order_by_expression\r\n order_by_expression\r\n
group_by_expression\r\n group_by_expression\r\n
limit_expression\r\n limit_expression\r\n
selection_domain\r\n selection_domain_from_expression\r\n
selection_report\r\n selection_domain_where_expression\r\n
selection_domain_catalog_alias_set\r\n
ignore_variation\r\n ignore_variation\r\n
standardize\r\n standardize\r\n
omit_simulation\r\n omit_simulation\r\n
......
...@@ -14,11 +14,9 @@ FROM ...@@ -14,11 +14,9 @@ FROM
<dtml-if expr="table_key != 'item'">, <dtml-var table_item> AS <dtml-var table_key></dtml-if> <dtml-if expr="table_key != 'item'">, <dtml-var table_item> AS <dtml-var table_key></dtml-if>
</dtml-in> </dtml-in>
</dtml-if> </dtml-if>
<dtml-if selection_domain>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_domain)"> </dtml-if> <dtml-if "selection_domain_from_expression">, <dtml-var "selection_domain_from_expression"> </dtml-if>
<dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if>
, item , item
<dtml-if join_on_item> <dtml-if join_on_item>
LEFT JOIN LEFT JOIN
item AS next_item item AS next_item
...@@ -65,12 +63,11 @@ WHERE ...@@ -65,12 +63,11 @@ WHERE
AND next_item.uid IS NULL AND next_item.uid IS NULL
</dtml-if> </dtml-if>
<dtml-if "selection_domain_where_expression">
<dtml-if selection_domain> <dtml-in selection_domain_catalog_alias_set>
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table='item', join_column='node_uid')"> AND <dtml-var stock_table_id>.<dtml-var sequence-item>_uid = <dtml-var sequence-item>.uid
</dtml-if> </dtml-in>
<dtml-if selection_report> AND <dtml-var "selection_domain_where_expression">
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, strict_membership=1)">
</dtml-if> </dtml-if>
<dtml-if group_by_expression> <dtml-if group_by_expression>
......
...@@ -198,8 +198,9 @@ input\r\n ...@@ -198,8 +198,9 @@ input\r\n
output\r\n output\r\n
from_table_list:list\r\n from_table_list:list\r\n
where_expression\r\n where_expression\r\n
selection_domain\r\n selection_domain_from_expression\r\n
selection_report\r\n selection_domain_where_expression\r\n
selection_domain_catalog_alias_set\r\n
order_by_expression\r\n order_by_expression\r\n
group_by_expression\r\n group_by_expression\r\n
join_on_item\r\n join_on_item\r\n
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment