Commit 370427b7 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 fcc11582
...@@ -678,6 +678,16 @@ class SimulationTool(BaseTool): ...@@ -678,6 +678,16 @@ class SimulationTool(BaseTool):
column_value_dict.setUIDList('section_uid', section) column_value_dict.setUIDList('section_uid', section)
column_value_dict.setUIDList('mirror_section_uid', mirror_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")
if isinstance(variation_category, basestring):
variation_category = (variation_category,)
variation_text = ["%{}%".format(x) for x in variation_category]
column_value_dict.setUIDList('variation_text', variation_text, column_value_dict.setUIDList('variation_text', variation_text,
as_text=1) as_text=1)
column_value_dict.setUIDList('sub_variation_text', sub_variation_text, column_value_dict.setUIDList('sub_variation_text', sub_variation_text,
...@@ -789,28 +799,6 @@ class SimulationTool(BaseTool): ...@@ -789,28 +799,6 @@ class SimulationTool(BaseTool):
}, },
'simulation_dict': self._getSimulationStateDict(**reserved_kw), '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_expression'] = '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 # build the group by expression
# if we group by a criterion, we also add this criterion to the select # if we group by a criterion, we also add this criterion to the select
......
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