Commit c609f284 authored by Vincent Pelletier's avatar Vincent Pelletier

SimulationTool: Stop relying on portal_selections for SQL expression generation

parent 012908b4
...@@ -80,8 +80,7 @@ FROM ...@@ -80,8 +80,7 @@ FROM
, <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
......
...@@ -599,6 +599,9 @@ class SimulationTool(BaseTool): ...@@ -599,6 +599,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):
""" """
...@@ -613,6 +616,30 @@ class SimulationTool(BaseTool): ...@@ -613,6 +616,30 @@ class SimulationTool(BaseTool):
# input and output are used by getTrackingList # input and output are used by getTrackingList
sql_kw['input'] = input sql_kw['input'] = input
sql_kw['output'] = output sql_kw['output'] = output
# selection_{domain,report}
portal = self.getPortalObject()
if selection_domain is None:
# Short-circuit DTML missing parameter lookup by always providing these
selection_domain_sql_dict = {
'from_expression': None,
'where_expression': None,
}
else:
# selection_domain has to be handled inside the ZSQLMethod as it does
# not apply to default query table (here, "stock") but to the catalog
# representing the "node". Hardcode table name to avoid calling from
# inside DTML.
selection_domain_sql_dict = portal.portal_catalog.buildSQLQuery(
selection_domain=selection_domain,
query_table_alias='node', # XXX: hard-coded value from ZSQLMethod
)
sql_kw['selection_domain_from_expression'] = selection_domain_sql_dict['from_expression']
sql_kw['selection_domain_where_expression'] = selection_domain_sql_dict['where_expression']
if selection_report is not None:
new_kw['selection_report'] = selection_report
# BBB
sql_kw['selection_domain'] = sql_kw['selection_report'] = None
# 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
...@@ -1185,7 +1212,6 @@ class SimulationTool(BaseTool): ...@@ -1185,7 +1212,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):
...@@ -1266,8 +1292,6 @@ class SimulationTool(BaseTool): ...@@ -1266,8 +1292,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,
...@@ -1890,8 +1914,7 @@ class SimulationTool(BaseTool): ...@@ -1890,8 +1914,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
...@@ -1907,8 +1930,7 @@ class SimulationTool(BaseTool): ...@@ -1907,8 +1930,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,
...@@ -1917,8 +1939,7 @@ class SimulationTool(BaseTool): ...@@ -1917,8 +1939,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
...@@ -1933,8 +1954,7 @@ class SimulationTool(BaseTool): ...@@ -1933,8 +1954,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,
...@@ -1944,7 +1964,6 @@ class SimulationTool(BaseTool): ...@@ -1944,7 +1964,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):
...@@ -1972,8 +1991,6 @@ class SimulationTool(BaseTool): ...@@ -1972,8 +1991,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=
...@@ -2072,7 +2089,6 @@ class SimulationTool(BaseTool): ...@@ -2072,7 +2089,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
...@@ -2178,8 +2194,6 @@ class SimulationTool(BaseTool): ...@@ -2178,8 +2194,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,11 @@ FROM ...@@ -75,8 +75,11 @@ 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_where_expression">
<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 "selection_domain_from_expression">, <dtml-var "selection_domain_from_expression"> </dtml-if>
, catalog AS node
</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 +105,9 @@ WHERE ...@@ -102,11 +105,9 @@ 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')"> AND <dtml-var stock_table_id>.node_uid = node.uid
</dtml-if> AND <dtml-var "selection_domain_where_expression">
<dtml-if selection_report>
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, category_table_alias='report_category', strict_membership=1)">
</dtml-if> </dtml-if>
<dtml-if convert_quantity_result> <dtml-if convert_quantity_result>
......
...@@ -27,9 +27,9 @@ from_expression\r\n ...@@ -27,9 +27,9 @@ 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
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,10 @@ FROM ...@@ -55,8 +55,10 @@ 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_where_expression">
<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 "selection_domain_from_expression">, <dtml-var "selection_domain_from_expression"> </dtml-if>
, catalog AS node
</dtml-if>
WHERE WHERE
stock.uid = catalog.uid stock.uid = catalog.uid
...@@ -132,11 +134,9 @@ WHERE ...@@ -132,11 +134,9 @@ 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')"> AND stock.node_uid = node.uid
</dtml-if> AND <dtml-var "selection_domain_where_expression">
<dtml-if selection_report>
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_report, category_table_alias='report_category', strict_membership=1)">
</dtml-if> </dtml-if>
<dtml-if group_by_expression> <dtml-if group_by_expression>
......
...@@ -424,8 +424,8 @@ where_expression\r\n ...@@ -424,8 +424,8 @@ 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
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,12 @@ FROM ...@@ -14,11 +14,12 @@ 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_where_expression">
<dtml-if selection_report>, <dtml-var "portal_selections.buildSQLJoinExpressionFromDomainSelection(selection_report)"> </dtml-if> <dtml-if "selection_domain_from_expression">, <dtml-var "selection_domain_from_expression"> </dtml-if>
, catalog AS node
</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 +66,9 @@ WHERE ...@@ -65,12 +66,9 @@ 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> AND stock.node_uid = node.uid
AND <dtml-var "portal_selections.buildSQLExpressionFromDomainSelection(selection_domain, join_table='item', 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 group_by_expression> <dtml-if group_by_expression>
...@@ -82,4 +80,4 @@ ORDER BY ...@@ -82,4 +80,4 @@ ORDER BY
<dtml-var order_by_expression> <dtml-var order_by_expression>
<dtml-else> <dtml-else>
ORDER BY item.date DESC ORDER BY item.date DESC
</dtml-if> </dtml-if>
\ No newline at end of file
...@@ -198,8 +198,8 @@ input\r\n ...@@ -198,8 +198,8 @@ 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
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