Commit 9beac557 authored by Jérome Perrin's avatar Jérome Perrin

InventoryAPI: implement variation_category as a layer over variation_text

Performance is still not optimal, but should be better than before. At
least it does not assume that movements will be in predicate table.
parent dbe28f3e
......@@ -678,6 +678,24 @@ class SimulationTool(BaseTool):
column_value_dict.setUIDList('section_uid', section)
column_value_dict.setUIDList('mirror_section_uid', mirror_section)
# Handle variation_category as variation_text
if variation_category:
if variation_text:
raise ValueError(
"Passing both variation_category and variation_text is not supported")
warn("variation_category is deprecated, please use variation_text instead",
DeprecationWarning)
if isinstance(variation_category, basestring):
variation_category = (variation_category,)
# variation text is a \n separated list of variation categories, but without
# trailing nor leading \n
variation_text = [
"{}\n%".format(x) for x in variation_category] + [
"%\n{}\n%".format(x) for x in variation_category] + [
"%\n{}".format(x) for x in variation_category] + [
"{}".format(x) for x in variation_category]
column_value_dict.setUIDList('variation_text', variation_text,
as_text=1)
column_value_dict.setUIDList('sub_variation_text', sub_variation_text,
......@@ -789,28 +807,6 @@ class SimulationTool(BaseTool):
},
'simulation_dict': self._getSimulationStateDict(**reserved_kw),
}
# It is necessary to use here another SQL query (or at least a subquery)
# to get _DISTINCT_ uid from predicate_category table.
# Otherwise, by using a where_expression, cells which fit conditions
# more than one time are counted more than one time, and the resulting
# inventory is false
# XXX Perhaps is there a better solution
add_kw = {}
if variation_category is not None and variation_category:
where_expression = self.getPortalObject().portal_categories\
.buildSQLSelector(
category_list = variation_category,
query_table = 'predicate_category')
if where_expression != '':
add_kw['where_expression'] = where_expression
add_kw['predicate_category.uid'] = '!=NULL'
add_kw['group_by'] = ['uid']
add_query = self.portal_catalog(**add_kw)
uid_list = []
for line in add_query:
uid_list.append(line.uid)
new_kw['where_expression'] = '( %s )' % ' OR '.join(
['catalog.uid=%s' % uid for uid in uid_list])
# build the group by expression
# if we group by a criterion, we also add this criterion to the select
......@@ -1012,7 +1008,8 @@ class SimulationTool(BaseTool):
variation_text
variation_category - variation or list of possible variations (it is not
a cross-search ; SQL query uses OR)
a cross-search ; SQL query uses OR).
Deprecated, use variation_text.
simulation_state - only take rows with specified simulation_state
......@@ -2133,6 +2130,7 @@ class SimulationTool(BaseTool):
XXX this way of implementing variation selection is far from perfect
variation_category - variation or list of possible variations
Deprecated, use variation_text
simulation_state - only take rows with specified simulation_state
......
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