[Erp5-report] r38862 jerome - in /erp5/trunk/products/ERP5: Document/ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Mon Oct 4 11:33:45 CEST 2010
Author: jerome
Date: Mon Oct 4 11:33:41 2010
New Revision: 38862
URL: http://svn.erp5.org?rev=38862&view=rev
Log:
variation can be multiple
Modified:
erp5/trunk/products/ERP5/Document/CategoryBudgetVariation.py
erp5/trunk/products/ERP5/Document/NodeBudgetVariation.py
erp5/trunk/products/ERP5/tests/testBudget.py
Modified: erp5/trunk/products/ERP5/Document/CategoryBudgetVariation.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/CategoryBudgetVariation.py?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/CategoryBudgetVariation.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/CategoryBudgetVariation.py [utf8] Mon Oct 4 11:33:41 2010
@@ -72,36 +72,45 @@ class CategoryBudgetVariation(BudgetVari
def getInventoryQueryDict(self, budget_cell):
""" Query dict to pass to simulation query
"""
+ query_dict = dict()
axis = self.getInventoryAxis()
if not axis:
- return dict()
+ return query_dict
base_category = self.getProperty('variation_base_category')
if not base_category:
- return dict()
+ return query_dict
context = budget_cell
if self.isMemberOf('budget_variation/budget'):
context = budget_cell.getParentValue().getParentValue()
elif self.isMemberOf('budget_variation/budget_line'):
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():
if '/' not in criterion_category: # safe ...
continue
criterion_base_category, category_url = criterion_category.split('/', 1)
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)
- # Different possible inventory axis here
- if axis == 'movement':
- return {'default_%s_uid' % base_category: category_uid}
- if axis == 'movement_strict_membership':
- return {'default_strict_%s_uid' % base_category: category_uid}
- if axis in ('node', 'section', 'payment', 'function', 'project',
- 'mirror_section', 'mirror_node' ):
- return {'%s_uid' % axis: category_uid}
- return {axis: criterion_category}
- return dict()
+ query_dict.setdefault(axis, []).append(category_uid)
+ else:
+ query_dict.setdefault(axis, []).append(criterion_category)
+
+ return query_dict
def getInventoryListQueryDict(self, budget_line):
"""Returns the query dict to pass to simulation query for a budget line
Modified: erp5/trunk/products/ERP5/Document/NodeBudgetVariation.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/Document/NodeBudgetVariation.py?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/Document/NodeBudgetVariation.py [utf8] (original)
+++ erp5/trunk/products/ERP5/Document/NodeBudgetVariation.py [utf8] Mon Oct 4 11:33:41 2010
@@ -125,12 +125,13 @@ class NodeBudgetVariation(BudgetVariatio
def getInventoryQueryDict(self, budget_cell):
""" Query dict to pass to simulation query
"""
+ query_dict = dict()
axis = self.getInventoryAxis()
if not axis:
- return dict()
+ return query_dict
base_category = self.getProperty('variation_base_category')
if not base_category:
- return dict()
+ return query_dict
budget_line = budget_cell.getParentValue()
context = budget_cell
@@ -138,6 +139,15 @@ class NodeBudgetVariation(BudgetVariatio
context = budget_line.getParentValue()
elif self.isMemberOf('budget_variation/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
for criterion_category in context.getMembershipCriterionCategoryList():
@@ -145,14 +155,6 @@ class NodeBudgetVariation(BudgetVariatio
continue
criterion_base_category, node_url = criterion_category.split('/', 1)
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():
# This is the "All Other" virtual node
other_uid_list = []
@@ -160,14 +162,16 @@ class NodeBudgetVariation(BudgetVariatio
if '%s/%s' % (base_category, node.getRelativeUrl()) in\
budget_line.getVariationCategoryList():
other_uid_list.append(node.getUid())
- return {axis: ComplexQuery(
+ query_dict.setdefault(axis, []).append(
+ ComplexQuery(
NegatedQuery(Query(**{axis: other_uid_list})),
Query(**{axis: None}),
- operator="OR")}
- return {axis:
- portal_categories.getCategoryValue(node_url, base_category=criterion_base_category).getUid()}
+ operator="OR"))
+ query_dict.setdefault(axis, []).append(
+ portal_categories.getCategoryValue(node_url,
+ base_category=criterion_base_category).getUid())
- return dict()
+ return query_dict
def getInventoryListQueryDict(self, budget_line):
"""Returns the query dict to pass to simulation query for a budget line
Modified: erp5/trunk/products/ERP5/tests/testBudget.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBudget.py?rev=38862&r1=38861&r2=38862&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBudget.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBudget.py [utf8] Mon Oct 4 11:33:41 2010
@@ -362,9 +362,9 @@ class TestBudget(ERP5TypeTestCase):
self.assertEquals(
dict(from_date=DateTime(2000, 1, 1),
at_date=DateTime(2000, 12, 31).latestTime(),
- node_category='account_type/expense',
- node_uid=self.portal.account_module.goods_purchase.getUid(),
- section_category='group/demo_group',),
+ node_category=['account_type/expense'],
+ node_uid=[self.portal.account_module.goods_purchase.getUid()],
+ section_category=['group/demo_group'],),
budget_model.getInventoryQueryDict(budget_cell))
budget_cell = budget_line.getCell('source/account_module/fixed_assets',
@@ -373,9 +373,9 @@ class TestBudget(ERP5TypeTestCase):
self.assertEquals(
dict(from_date=DateTime(2000, 1, 1),
at_date=DateTime(2000, 12, 31).latestTime(),
- node_category='account_type/asset',
- node_uid=self.portal.account_module.fixed_assets.getUid(),
- section_category='group/demo_group',),
+ node_category=['account_type/asset'],
+ node_uid=[self.portal.account_module.fixed_assets.getUid()],
+ section_category=['group/demo_group'],),
budget_model.getInventoryQueryDict(budget_cell))
self.assertEquals(
@@ -964,7 +964,74 @@ class TestBudget(ERP5TypeTestCase):
{('source/account_module/goods_purchase', ): 100.0, },
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
def test_budget_consumption_report(self):
budget_model = self.portal.budget_model_module.newContent(
More information about the Erp5-report
mailing list