Commit cb456593 authored by Jérome Perrin's avatar Jérome Perrin

variation can be multiple


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@38862 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 42eba846
...@@ -72,36 +72,45 @@ class CategoryBudgetVariation(BudgetVariation): ...@@ -72,36 +72,45 @@ class CategoryBudgetVariation(BudgetVariation):
def getInventoryQueryDict(self, budget_cell): def getInventoryQueryDict(self, budget_cell):
""" Query dict to pass to simulation query """ Query dict to pass to simulation query
""" """
query_dict = dict()
axis = self.getInventoryAxis() axis = self.getInventoryAxis()
if not axis: if not axis:
return dict() return query_dict
base_category = self.getProperty('variation_base_category') base_category = self.getProperty('variation_base_category')
if not base_category: if not base_category:
return dict() return query_dict
context = budget_cell context = budget_cell
if self.isMemberOf('budget_variation/budget'): if self.isMemberOf('budget_variation/budget'):
context = budget_cell.getParentValue().getParentValue() context = budget_cell.getParentValue().getParentValue()
elif self.isMemberOf('budget_variation/budget_line'): elif self.isMemberOf('budget_variation/budget_line'):
context = budget_cell.getParentValue() context = budget_cell.getParentValue()
uid_based_axis = False
if axis == 'movement':
axis = 'default_%s_uid' % base_category
uid_based_axis = True
elif axis == 'movement_strict_membership':
axis = 'default_strict_%s_uid' % base_category
uid_based_axis = True
elif axis in ('node', 'section', 'payment', 'function', 'project',
'mirror_section', 'mirror_node' ):
axis = '%s_uid' % axis
uid_based_axis = True
for criterion_category in context.getMembershipCriterionCategoryList(): for criterion_category in context.getMembershipCriterionCategoryList():
if '/' not in criterion_category: # safe ... if '/' not in criterion_category: # safe ...
continue continue
criterion_base_category, category_url = criterion_category.split('/', 1) criterion_base_category, category_url = criterion_category.split('/', 1)
if criterion_base_category == base_category: if criterion_base_category == base_category:
category_uid = self.getPortalObject().portal_categories\ if uid_based_axis:
category_uid = self.getPortalObject().portal_categories\
.getCategoryUid(criterion_category) .getCategoryUid(criterion_category)
# Different possible inventory axis here query_dict.setdefault(axis, []).append(category_uid)
if axis == 'movement': else:
return {'default_%s_uid' % base_category: category_uid} query_dict.setdefault(axis, []).append(criterion_category)
if axis == 'movement_strict_membership':
return {'default_strict_%s_uid' % base_category: category_uid} return query_dict
if axis in ('node', 'section', 'payment', 'function', 'project',
'mirror_section', 'mirror_node' ):
return {'%s_uid' % axis: category_uid}
return {axis: criterion_category}
return dict()
def getInventoryListQueryDict(self, budget_line): def getInventoryListQueryDict(self, budget_line):
"""Returns the query dict to pass to simulation query for a budget line """Returns the query dict to pass to simulation query for a budget line
......
...@@ -125,12 +125,13 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -125,12 +125,13 @@ class NodeBudgetVariation(BudgetVariation):
def getInventoryQueryDict(self, budget_cell): def getInventoryQueryDict(self, budget_cell):
""" Query dict to pass to simulation query """ Query dict to pass to simulation query
""" """
query_dict = dict()
axis = self.getInventoryAxis() axis = self.getInventoryAxis()
if not axis: if not axis:
return dict() return query_dict
base_category = self.getProperty('variation_base_category') base_category = self.getProperty('variation_base_category')
if not base_category: if not base_category:
return dict() return query_dict
budget_line = budget_cell.getParentValue() budget_line = budget_cell.getParentValue()
context = budget_cell context = budget_cell
...@@ -138,6 +139,15 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -138,6 +139,15 @@ class NodeBudgetVariation(BudgetVariation):
context = budget_line.getParentValue() context = budget_line.getParentValue()
elif self.isMemberOf('budget_variation/budget_line'): elif self.isMemberOf('budget_variation/budget_line'):
context = budget_line context = budget_line
if axis == 'movement':
axis = 'default_%s' % base_category
if axis == 'movement_strict_membership':
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
# parameters such as section_category_uid
axis = '%s_uid' % axis
portal_categories = self.getPortalObject().portal_categories portal_categories = self.getPortalObject().portal_categories
for criterion_category in context.getMembershipCriterionCategoryList(): for criterion_category in context.getMembershipCriterionCategoryList():
...@@ -145,14 +155,6 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -145,14 +155,6 @@ class NodeBudgetVariation(BudgetVariation):
continue continue
criterion_base_category, node_url = criterion_category.split('/', 1) criterion_base_category, node_url = criterion_category.split('/', 1)
if criterion_base_category == base_category: if criterion_base_category == base_category:
if axis == 'movement':
axis = 'default_%s' % base_category
if axis == 'movement_strict_membership':
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
# parameters such as section_category_uid
axis = '%s_uid' % axis
if node_url == budget_line.getRelativeUrl(): if node_url == budget_line.getRelativeUrl():
# This is the "All Other" virtual node # This is the "All Other" virtual node
other_uid_list = [] other_uid_list = []
...@@ -160,14 +162,16 @@ class NodeBudgetVariation(BudgetVariation): ...@@ -160,14 +162,16 @@ class NodeBudgetVariation(BudgetVariation):
if '%s/%s' % (base_category, node.getRelativeUrl()) in\ if '%s/%s' % (base_category, node.getRelativeUrl()) in\
budget_line.getVariationCategoryList(): budget_line.getVariationCategoryList():
other_uid_list.append(node.getUid()) other_uid_list.append(node.getUid())
return {axis: ComplexQuery( query_dict.setdefault(axis, []).append(
ComplexQuery(
NegatedQuery(Query(**{axis: other_uid_list})), NegatedQuery(Query(**{axis: other_uid_list})),
Query(**{axis: None}), Query(**{axis: None}),
operator="OR")} operator="OR"))
return {axis: query_dict.setdefault(axis, []).append(
portal_categories.getCategoryValue(node_url, base_category=criterion_base_category).getUid()} portal_categories.getCategoryValue(node_url,
base_category=criterion_base_category).getUid())
return dict() return query_dict
def getInventoryListQueryDict(self, budget_line): def getInventoryListQueryDict(self, budget_line):
"""Returns the query dict to pass to simulation query for a budget line """Returns the query dict to pass to simulation query for a budget line
......
...@@ -362,9 +362,9 @@ class TestBudget(ERP5TypeTestCase): ...@@ -362,9 +362,9 @@ class TestBudget(ERP5TypeTestCase):
self.assertEquals( self.assertEquals(
dict(from_date=DateTime(2000, 1, 1), dict(from_date=DateTime(2000, 1, 1),
at_date=DateTime(2000, 12, 31).latestTime(), at_date=DateTime(2000, 12, 31).latestTime(),
node_category='account_type/expense', node_category=['account_type/expense'],
node_uid=self.portal.account_module.goods_purchase.getUid(), node_uid=[self.portal.account_module.goods_purchase.getUid()],
section_category='group/demo_group',), section_category=['group/demo_group'],),
budget_model.getInventoryQueryDict(budget_cell)) budget_model.getInventoryQueryDict(budget_cell))
budget_cell = budget_line.getCell('source/account_module/fixed_assets', budget_cell = budget_line.getCell('source/account_module/fixed_assets',
...@@ -373,9 +373,9 @@ class TestBudget(ERP5TypeTestCase): ...@@ -373,9 +373,9 @@ class TestBudget(ERP5TypeTestCase):
self.assertEquals( self.assertEquals(
dict(from_date=DateTime(2000, 1, 1), dict(from_date=DateTime(2000, 1, 1),
at_date=DateTime(2000, 12, 31).latestTime(), at_date=DateTime(2000, 12, 31).latestTime(),
node_category='account_type/asset', node_category=['account_type/asset'],
node_uid=self.portal.account_module.fixed_assets.getUid(), node_uid=[self.portal.account_module.fixed_assets.getUid()],
section_category='group/demo_group',), section_category=['group/demo_group'],),
budget_model.getInventoryQueryDict(budget_cell)) budget_model.getInventoryQueryDict(budget_cell))
self.assertEquals( self.assertEquals(
...@@ -964,7 +964,74 @@ class TestBudget(ERP5TypeTestCase): ...@@ -964,7 +964,74 @@ class TestBudget(ERP5TypeTestCase):
{('source/account_module/goods_purchase', ): 100.0, }, {('source/account_module/goods_purchase', ): 100.0, },
budget_line.getEngagedBudgetDict()) budget_line.getEngagedBudgetDict())
def test_multiple_variation_line_level(self):
# tests the behaviour of getInventoryListQueryDict and
# getInventoryQueryDict when we are using budget line level variation with
# multiple variation set. It should be a 'OR' between all the selected
# variations.
budget_model = self.portal.budget_model_module.newContent(
portal_type='Budget Model')
budget_model.newContent(
portal_type='Node Budget Variation',
int_index=1,
budget_variation='budget_line',
inventory_axis='node',
variation_base_category='source',
aggregate_value_list=(
self.portal.account_module.goods_purchase,
self.portal.account_module.fixed_assets,
))
budget_model.newContent(
portal_type='Category Budget Variation',
int_index=2,
budget_variation='budget_line',
inventory_axis='section_category',
variation_base_category='group',)
# this variation will be needed to create cells
budget_model.newContent(
portal_type='Category Budget Variation',
int_index=3,
budget_variation='budget_cell',
inventory_axis='node_category_strict_membership',
variation_base_category='account_type',)
budget = self.portal.budget_module.newContent(
portal_type='Budget',
specialise_value=budget_model)
budget_line = budget.newContent(portal_type='Budget Line')
budget_line.edit(
variation_category_list=['group/demo_group/sub1',
'group/demo_group/sub2',
'source/account_module/goods_purchase',
'source/account_module/fixed_assets',
])
self.assertEquals({
'from_date': None,
'group_by_node': True,
'group_by_section_category': True,
'section_category': ['group/demo_group/sub1',
'group/demo_group/sub2'],
'node_uid': [self.portal.account_module.goods_purchase.getUid(),
self.portal.account_module.fixed_assets.getUid()], },
budget_model.getInventoryListQueryDict(budget_line))
self.assertEquals({
'from_date': None,
'simulation_state': ('delivered', 'stopped'),
# XXX order is reversed for some reason ...
'section_category': ['group/demo_group/sub2',
'group/demo_group/sub1'],
'node_uid': [self.portal.account_module.fixed_assets.getUid(),
self.portal.account_module.goods_purchase.getUid()],
'node_category_strict_membership': ['account_type/expense']},
# BudgetLine_getInventoryQueryDictForCellIndex uses getInventoryQueryDict
# but does not require the cell to be physically present
budget_line.BudgetLine_getInventoryQueryDictForCellIndex(
cell_index=('account_type/expense')))
# Report # Report
def test_budget_consumption_report(self): def test_budget_consumption_report(self):
budget_model = self.portal.budget_model_module.newContent( budget_model = self.portal.budget_model_module.newContent(
......
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