Commit 53fc65cd authored by Jérome Perrin's avatar Jérome Perrin

support category inventory axis (such as node_category) for NodeBudgetVariation


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42400 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 30acf114
...@@ -125,10 +125,12 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -125,10 +125,12 @@ class NodeBudgetVariation(BudgetVariation):
axis = 'default_%s' % base_category axis = 'default_%s' % base_category
if axis == 'movement_strict_membership': if axis == 'movement_strict_membership':
axis = 'default_strict_%s' % base_category axis = 'default_strict_%s' % base_category
# TODO: This is not correct if axis is a category such as
# section_category, because getInventoryList for now does not support uid_based_axis = False
# parameters such as section_category_uid if axis in ('node', 'section', 'payment', 'function', 'project',
axis = '%s_uid' % axis 'mirror_section', 'mirror_node' ):
axis = '%s_uid' % axis
uid_based_axis = True
query = None query = None
portal_categories = self.getPortalObject().portal_categories portal_categories = self.getPortalObject().portal_categories
...@@ -150,7 +152,10 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -150,7 +152,10 @@ class NodeBudgetVariation(BudgetVariation):
if node.getRelativeUrl() == 'budget_special_node/none': if node.getRelativeUrl() == 'budget_special_node/none':
none_node_selected = True none_node_selected = True
else: else:
other_uid_list.append(node.getUid()) if uid_based_axis:
other_uid_list.append(node.getUid())
else:
other_uid_list.append(node.getRelativeUrl())
if none_node_selected: if none_node_selected:
# in this case we don't want to include NULL in All others # in this case we don't want to include NULL in All others
query = NegatedQuery(Query(**{axis: other_uid_list})) query = NegatedQuery(Query(**{axis: other_uid_list}))
...@@ -161,9 +166,12 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -161,9 +166,12 @@ class NodeBudgetVariation(BudgetVariation):
operator="OR") operator="OR")
else: else:
query_dict.setdefault(axis, []).append( value = portal_categories.getCategoryValue(node_url,
portal_categories.getCategoryValue(node_url, base_category=criterion_base_category)
base_category=criterion_base_category).getUid()) if uid_based_axis:
query_dict.setdefault(axis, []).append(value.getUid())
else:
query_dict.setdefault(axis, []).append(value.getRelativeUrl())
if query: if query:
if axis in query_dict: if axis in query_dict:
...@@ -204,9 +212,11 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -204,9 +212,11 @@ class NodeBudgetVariation(BudgetVariation):
else: else:
query_dict['group_by_%s' % axis] = True query_dict['group_by_%s' % axis] = True
# TODO: This is not correct if axis is a category (such as uid_based_axis = False
# section_category) if axis in ('node', 'section', 'payment', 'function', 'project',
axis = '%s_uid' % axis 'mirror_section', 'mirror_node' ):
axis = '%s_uid' % axis
uid_based_axis = True
# if we have a virtual "all others" node, we don't set a criterion here. # if we have a virtual "all others" node, we don't set a criterion here.
if self.getProperty('include_virtual_other_node'): if self.getProperty('include_virtual_other_node'):
...@@ -216,9 +226,15 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -216,9 +226,15 @@ class NodeBudgetVariation(BudgetVariation):
for node_url in context.getVariationCategoryList( for node_url in context.getVariationCategoryList(
base_category_list=(base_category,)): base_category_list=(base_category,)):
if node_url != '%s/budget_special_node/none' % base_category: if node_url != '%s/budget_special_node/none' % base_category:
query_dict.setdefault(axis, []).append( __traceback_info__ = (node_url, )
if uid_based_axis:
query_dict.setdefault(axis, []).append(
portal_categories.getCategoryValue(node_url, portal_categories.getCategoryValue(node_url,
base_category=base_category).getUid()) base_category=base_category).getUid())
else:
query_dict.setdefault(axis, []).append(
portal_categories.getCategoryValue(node_url,
base_category=base_category).getRelativeUrl())
found = True found = True
if found: if found:
if self.getProperty('include_virtual_none_node'): if self.getProperty('include_virtual_none_node'):
...@@ -260,7 +276,7 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -260,7 +276,7 @@ class NodeBudgetVariation(BudgetVariation):
for node in self._getNodeList(budget_line)] for node in self._getNodeList(budget_line)]
def getBudgetVariationRangeCategoryList(self, budget): def getBudgetVariationRangeCategoryList(self, budget):
"""Returns the Variation Range Category Listhat can be applied to this """Returns the Variation Range Category List that can be applied to this
budget. budget.
""" """
base_category = self.getProperty('variation_base_category') base_category = self.getProperty('variation_base_category')
......
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