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

introduce BudgetLine.getAvailableBudgetDict


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37225 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0f337f57
......@@ -83,6 +83,25 @@ class BudgetLine(Predicate, XMLMatrix, Variated):
self.getPortalTransitInventoryStateList())
return self._getBudgetDict(**kw)
security.declareProtected(Permissions.AccessContentsInformation,
'getAvailableBudgetDict')
def getAvailableBudgetDict(self, **kw):
"""Returns all the engagements in a dict where the keys are the cells, and
the value is the engaged budget.
"""
budget_dict = dict([(k, v * -1) for (k,v) in
self.getEngagedBudgetDict(**kw).items()])
cell_key_list = self.getCellKeyList()
for cell_key in cell_key_list:
cell_key = tuple(cell_key)
cell = self.getCell(*cell_key)
if cell is not None:
engaged = budget_dict.get(cell_key, 0)
budget_dict[cell_key] = cell.getCurrentBalance() + engaged
return budget_dict
def _getBudgetDict(self, **kw):
"""Use getCurrentInventoryList to compute all budget cell consumptions at
once, and returns them in a dict.
......
......@@ -363,7 +363,17 @@ class TestBudget(ERP5TypeTestCase):
{('source/account_module/fixed_assets', 'account_type/asset'): -100.0,
('source/account_module/goods_purchase', 'account_type/expense'): 100.0},
budget_line.getEngagedBudgetDict())
self.assertEquals(
{('source/account_module/fixed_assets', 'account_type/asset'): 102.0,
('source/account_module/goods_purchase', 'account_type/expense'): -99.0},
budget_line.getAvailableBudgetDict())
# we can view the forms without error
budget_line.BudgetLine_viewEngagedBudget()
budget_line.BudgetLine_viewConsumedBudget()
budget_line.BudgetLine_viewAvailableBudget()
def test_all_other_and_strict_consumption(self):
# tests consumptions, by using "all other" virtual node on a node budget
# variation, and strict membership on category budget variation
......@@ -476,6 +486,11 @@ class TestBudget(ERP5TypeTestCase):
{('source/%s' % budget_line.getRelativeUrl(), 'account_type/asset'): -100.0,
('source/account_module/goods_purchase', 'account_type/expense'): 100.0},
budget_line.getEngagedBudgetDict())
self.assertEquals(
{('source/%s' % budget_line.getRelativeUrl(), 'account_type/asset'): 102.0,
('source/account_module/goods_purchase', 'account_type/expense'): -99.0},
budget_line.getAvailableBudgetDict())
def test_consumption_movement_category(self):
......@@ -612,6 +627,15 @@ class TestBudget(ERP5TypeTestCase):
},
budget_line.getEngagedBudgetDict())
self.assertEquals(
{('source/account_module/fixed_assets', 'product_line/1/1.2'): 100.0,
('source/account_module/goods_purchase', 'product_line/1/1.1'): -98.0,
# summary line is automatically added (TODO)
## ('source/account_module/goods_purchase', 'product_line/1'): 98.0
('source/account_module/goods_purchase', 'product_line/1'): 2.0
},
budget_line.getAvailableBudgetDict())
# Other TODOs:
......
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