[Erp5-report] r37236 jerome - /erp5/trunk/products/ERP5/tests/testBudget.py
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Jul 22 10:37:32 CEST 2010
Author: jerome
Date: Thu Jul 22 10:37:28 2010
New Revision: 37236
URL: http://svn.erp5.org?rev=37236&view=rev
Log:
test budget consumptions report
Modified:
erp5/trunk/products/ERP5/tests/testBudget.py
Modified: erp5/trunk/products/ERP5/tests/testBudget.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5/tests/testBudget.py?rev=37236&r1=37235&r2=37236&view=diff
==============================================================================
--- erp5/trunk/products/ERP5/tests/testBudget.py [utf8] (original)
+++ erp5/trunk/products/ERP5/tests/testBudget.py [utf8] Thu Jul 22 10:37:28 2010
@@ -637,10 +637,159 @@ class TestBudget(ERP5TypeTestCase):
budget_line.getAvailableBudgetDict())
- # Other TODOs:
+ def test_budget_consumption_report(self):
+ budget_model = self.portal.budget_model_module.newContent(
+ portal_type='Budget Model')
+ budget_model.newContent(
+ portal_type='Category Budget Variation',
+ int_index=1,
+ budget_variation='budget',
+ inventory_axis='section_category',
+ variation_base_category='group',)
+ budget_model.newContent(
+ portal_type='Node Budget Variation',
+ int_index=2,
+ budget_variation='budget_cell',
+ 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=3,
+ budget_variation='budget_cell',
+ inventory_axis='node_category',
+ variation_base_category='account_type',)
+
+ budget = self.portal.budget_module.newContent(
+ portal_type='Budget',
+ title='Budget Title',
+ start_date_range_min=DateTime(2000, 1, 1),
+ start_date_range_max=DateTime(2000, 12, 31),
+ specialise_value=budget_model)
+
+ budget.edit(variation_category_list=['group/demo_group'])
+ budget_line = budget.newContent(portal_type='Budget Line',
+ title='Budget Line Title',)
+
+ # set the range, this will adjust the matrix
+ budget_line.edit(
+ variation_category_list=(
+ 'source/account_module/goods_purchase',
+ 'source/account_module/fixed_assets',
+ 'account_type/asset', ))
+
+ # simuate a request and call Base_edit, which does all the work of creating
+ # cell and setting cell properties.
+ form = budget_line.BudgetLine_view
+ self.portal.REQUEST.other.update(
+ dict(AUTHENTICATED_USER=getSecurityManager().getUser(),
+
+ field_membership_criterion_base_category_list=
+ form.membership_criterion_base_category_list.get_value('default'),
+ field_mapped_value_property_list=
+ form.mapped_value_property_list.get_value('default'),
+
+ field_matrixbox_quantity_cell_0_0_0="",
+ field_matrixbox_membership_criterion_category_list_cell_0_0_0=[],
+ field_matrixbox_quantity_cell_1_0_0="200",
+ field_matrixbox_membership_criterion_category_list_cell_1_0_0=[
+ 'source/account_module/fixed_assets',
+ 'account_type/asset'],
+ ))
+ budget_line.Base_edit(form_id=form.getId())
+
+ atransaction = self.portal.accounting_module.newContent(
+ portal_type='Accounting Transaction',
+ resource_value=self.portal.currency_module.euro,
+ source_section_value=self.portal.organisation_module.my_organisation,
+ start_date=DateTime(2000, 1, 2))
+ atransaction.newContent(
+ portal_type='Accounting Transaction Line',
+ source_value=self.portal.account_module.goods_purchase,
+ source_credit=100)
+ atransaction.newContent(
+ portal_type='Accounting Transaction Line',
+ source_value=self.portal.account_module.fixed_assets,
+ source_debit=100)
+ atransaction.stop()
+
+ transaction.commit()
+ self.tic()
+
+ # Budget_getBudgetConsumptionReportData returns all the data for the report
+ line_list, line_count = budget.Budget_getBudgetConsumptionReportData()
+ # the number of lines, which will be used in the report to set the print
+ # range
+ self.assertEquals(6, line_count)
+ # number of line can be different from the length of the line list, because
+ # line list is a recursive structure.
+ self.assertEquals(4, len(line_list))
+
+ # first line is for the title of the budget
+ self.assertEquals('Budget Title', line_list[0]['title'])
+ self.assertTrue(line_list[0]['is_budget'])
+
+ # then we have a first level for budget lines
+ self.assertEquals('Budget Line Title', line_list[1]['title'])
+ self.assertTrue(line_list[1]['is_level_1'])
+ # we can see global consumptions for the budget
+ self.assertEquals(200, line_list[2]['initial_budget'])
+ self.assertEquals(200, line_list[2]['current_budget'])
+ self.assertEquals(100, line_list[2]['consumed_budget'])
+ self.assertEquals(100, line_list[2]['engaged_budget'])
+ self.assertEquals(.5, line_list[2]['consumed_ratio'])
+
+ # the dimensions are reversed in the budget report, so on level 2 we have
+ # the last dimension from cell range, here "account type"
+ self.assertEquals('Asset', line_list[2]['title'])
+ # we can see global consumptions for that summary line
+ self.assertEquals(200, line_list[2]['initial_budget'])
+ self.assertEquals(200, line_list[2]['current_budget'])
+ self.assertEquals(100, line_list[2]['consumed_budget'])
+ self.assertEquals(100, line_list[2]['engaged_budget'])
+ self.assertEquals(.5, line_list[2]['consumed_ratio'])
+
+ # no we have a recursive list, for the next dimension: node.
+ self.assertTrue(isinstance(line_list[3], list))
+ self.assertEquals(3, len(line_list[3]))
+
+ # first is again a title XXX why ??
+ self.assertEquals('Asset', line_list[3][0]['title'])
+ # then we have two level 3 cells
+ self.assertTrue(line_list[3][1]['is_level_3'])
+ self.assertEquals('Goods Purchase', line_list[3][1]['title'])
+ self.assertEquals(0, line_list[3][1]['initial_budget'])
+ self.assertEquals(0, line_list[3][1]['current_budget'])
+ self.assertEquals(0, line_list[3][1]['consumed_budget'])
+ self.assertEquals(0, line_list[3][1]['engaged_budget'])
+ self.assertEquals(0, line_list[3][1]['consumed_ratio'])
+
+ self.assertEquals('Fixed Assets', line_list[3][2]['title'])
+ self.assertEquals(200, line_list[3][2]['initial_budget'])
+ self.assertEquals(200, line_list[3][2]['current_budget'])
+ self.assertEquals(100, line_list[3][2]['consumed_budget'])
+ self.assertEquals(100, line_list[3][2]['engaged_budget'])
+ self.assertEquals(.5, line_list[3][2]['consumed_ratio'])
+
+ # validate report ODF
+ from Products.ERP5OOo.tests.utils import Validator
+ odf_validator = Validator()
+ odf = budget.Budget_viewBudgetConsumptionReport()
+ err_list = odf_validator.validate(odf)
+ if err_list:
+ self.fail(''.join(err_list))
+
+
+ # Other TODOs:
# section_category & summary
+ # budget level variation and budget cell level variation for same inventory
+ # axis
+
# resource/price currency on budget ?
# test virtual all others when cloning an existing budget
More information about the Erp5-report
mailing list