Commit 89f11153 authored by Jérome Perrin's avatar Jérome Perrin

update budget consumption report to use BudgetLine_getConsumedBudgetDict and...

update budget consumption report to use BudgetLine_getConsumedBudgetDict and BudgetLine_getSummaryDimensionKeyDict

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@37283 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 476ec3f7
...@@ -119,15 +119,18 @@ if request.get(\'price_currency\'):\n ...@@ -119,15 +119,18 @@ if request.get(\'price_currency\'):\n
target_currency_title = target_currency.getReference()\n target_currency_title = target_currency.getReference()\n
\n \n
\n \n
def isVisibleCell(cell):\n def isVisibleCell(cell_key):\n
# can this cell be viewed by this user ?\n # can this cell be viewed by this user ?\n
for category in cell.getMembershipCriterionCategoryList():\n for category in cell_key:\n
if category.startswith(\'group/\'):\n if category.startswith(\'group/\'):\n
if not category.startswith(defined_group):\n if not category.startswith(defined_group):\n
return False\n return False\n
return True\n return True\n
\n \n
\n \n
\n
\n
\n
# in this report, level 1 is the budget line structure,\n # in this report, level 1 is the budget line structure,\n
# level 2 is the first variation category\n # level 2 is the first variation category\n
# level 3 is the second variation category\n # level 3 is the second variation category\n
...@@ -135,6 +138,8 @@ def isVisibleCell(cell):\n ...@@ -135,6 +138,8 @@ def isVisibleCell(cell):\n
for budget in budget_list:\n for budget in budget_list:\n
\n \n
if target_currency is not None:\n if target_currency is not None:\n
# FIXME: this target currency support is not supported and have to be\n
# rewritten / removed\n
conversion_ratio = target_currency.getPrice(\n conversion_ratio = target_currency.getPrice(\n
context=budget.asContext(\n context=budget.asContext(\n
categories=[\n categories=[\n
...@@ -153,7 +158,7 @@ for budget in budget_list:\n ...@@ -153,7 +158,7 @@ for budget in budget_list:\n
resource_title=budget.getResource() and\n resource_title=budget.getResource() and\n
budget.getResourceReference()))\n budget.getResourceReference()))\n
\n \n
# XXX to get the count of lines correct (for the print range)\n # To get the count of lines correct (for the print range)\n
if target_currency_title:\n if target_currency_title:\n
line_list.append(dict())\n line_list.append(dict())\n
\n \n
...@@ -166,7 +171,14 @@ for budget in budget_list:\n ...@@ -166,7 +171,14 @@ for budget in budget_list:\n
\n \n
level_1_line_list = []\n level_1_line_list = []\n
\n \n
consumed_budget_dict = budget_line.getConsumedBudgetDict()\n
engaged_budget_dict = budget_line.getEngagedBudgetDict()\n
budget_line_cell_range = budget_line.BudgetLine_asCellRange()\n budget_line_cell_range = budget_line.BudgetLine_asCellRange()\n
budget_line_as_cell_range_matrixbox =\\\n
budget_line.BudgetLine_asCellRange(matrixbox=1)\n
\n
dependant_dimension_dict = budget_line.BudgetLine_getSummaryDimensionKeyDict()\n
\n
if len(budget_line_cell_range) == 0:\n if len(budget_line_cell_range) == 0:\n
continue\n continue\n
if len(budget_line_cell_range) == 1:\n if len(budget_line_cell_range) == 1:\n
...@@ -192,9 +204,8 @@ for budget in budget_list:\n ...@@ -192,9 +204,8 @@ for budget in budget_list:\n
cell_style_dict = {budget_line.getResource(base=1): \'Level2\'}\n cell_style_dict = {budget_line.getResource(base=1): \'Level2\'}\n
cell_depth_dict = {budget_line.getResource(base=1): 0}\n cell_depth_dict = {budget_line.getResource(base=1): 0}\n
\n \n
# calculate the depth for styling\n
min_depth = 100\n min_depth = 100\n
budget_line_as_cell_range_matrixbox =\\\n
budget_line.BudgetLine_asCellRange(matrixbox=1)\n
for cell_range_list in budget_line_as_cell_range_matrixbox:\n for cell_range_list in budget_line_as_cell_range_matrixbox:\n
for category, title in cell_range_list:\n for category, title in cell_range_list:\n
if category in level_2_variation_category_list:\n if category in level_2_variation_category_list:\n
...@@ -218,12 +229,6 @@ for budget in budget_list:\n ...@@ -218,12 +229,6 @@ for budget in budget_list:\n
cell_style_dict[category] = \'Level2.3\'\n cell_style_dict[category] = \'Level2.3\'\n
else:\n else:\n
cell_style_dict[category] = \'Level2\'\n cell_style_dict[category] = \'Level2\'\n
\n
# We\'ll only sum level 2 budget cells if they are the shallowest in the\n
# category tree\n
higher_depth = min_depth\n
if cell_depth_dict:\n
higher_depth = min(cell_depth_dict.values())\n
\n \n
sign = budget_line.BudgetLine_getConsumptionSign()\n sign = budget_line.BudgetLine_getConsumptionSign()\n
\n \n
...@@ -238,7 +243,7 @@ for budget in budget_list:\n ...@@ -238,7 +243,7 @@ for budget in budget_list:\n
title=cell_name_dict[level_2_category],\n title=cell_name_dict[level_2_category],\n
style=cell_style_dict[level_2_category])]\n style=cell_style_dict[level_2_category])]\n
\n \n
is_higher_level2 = cell_depth_dict[level_2_category] == higher_depth\n is_higher_level2 = level_2_category not in dependant_dimension_dict\n
\n \n
for level_3_category in level_3_variation_category_list:\n for level_3_category in level_3_variation_category_list:\n
total_level_3_initial_budget = 0\n total_level_3_initial_budget = 0\n
...@@ -249,6 +254,8 @@ for budget in budget_list:\n ...@@ -249,6 +254,8 @@ for budget in budget_list:\n
\n \n
level_3_line_list = [dict(is_level_3=True,\n level_3_line_list = [dict(is_level_3=True,\n
title=cell_name_dict[level_3_category],)]\n title=cell_name_dict[level_3_category],)]\n
\n
is_higher_level3 = level_3_category not in dependant_dimension_dict\n
\n \n
for level_4_category in level_4_variation_category_list:\n for level_4_category in level_4_variation_category_list:\n
# TODO: maybe fail if only 1 dimension ...\n # TODO: maybe fail if only 1 dimension ...\n
...@@ -256,36 +263,50 @@ for budget in budget_list:\n ...@@ -256,36 +263,50 @@ for budget in budget_list:\n
cell_key = (level_3_category, level_2_category)\n cell_key = (level_3_category, level_2_category)\n
else:\n else:\n
cell_key = (level_4_category, level_3_category, level_2_category)\n cell_key = (level_4_category, level_3_category, level_2_category)\n
\n \n
if not isVisibleCell(cell_key):\n
continue\n
\n
consumed_budget = consumed_budget_dict.get(cell_key, None)\n
engaged_budget = engaged_budget_dict.get(cell_key, None)\n
cell = budget_line.getCell(*cell_key)\n cell = budget_line.getCell(*cell_key)\n
if cell is None or not isVisibleCell(cell):\n if cell is None \\\n
and consumed_budget is None \\\n
and engaged_budget is None:\n
continue\n continue\n
\n \n
initial_budget = cell.getQuantity() * sign\n if not consumed_budget:\n
consumed_budget = 0\n
if not engaged_budget:\n
engaged_budget = 0\n
\n
initial_budget = None\n
if cell is not None:\n
initial_budget = cell.getQuantity() * sign\n
\n \n
# XXX don\'t calculate current balance unless we use budget\n # XXX don\'t calculate current balance unless we use budget\n
# transactions\n # transactions\n
current_budget = initial_budget #cell.getCurrentBalance() * sign\n current_budget = initial_budget #cell.getCurrentBalance() * sign\n
\n \n
engaged_budget = cell.getEngagedBudget()\n
\n \n
# XXX stupid optimisation that may not always be true: \n # XXX stupid optimisation that may not always be true: \n
# if there\'s no engaged budget, there\'s no consumed budget\n # if there\'s no engaged budget, there\'s no consumed budget\n
if engaged_budget:\n if engaged_budget:\n
consumed_budget = cell.getConsumedBudget()\n
# XXX calculate manually getAvailableBudget, because it calls\n # XXX calculate manually getAvailableBudget, because it calls\n
# getEngagedBudget again\n # getEngagedBudget again\n
# available_budget = cell.getAvailableBudget()\n # available_budget = cell.getAvailableBudget()\n
available_budget = current_budget - engaged_budget\n available_budget = (current_budget or 0) - engaged_budget\n
else:\n else:\n
consumed_budget = 0\n
available_budget = current_budget\n available_budget = current_budget\n
\n \n
total_level_3_initial_budget += initial_budget\n if initial_budget:\n
total_level_3_current_budget += current_budget\n total_level_3_initial_budget += initial_budget\n
if current_budget:\n
total_level_3_current_budget += current_budget\n
total_level_3_engaged_budget += engaged_budget\n total_level_3_engaged_budget += engaged_budget\n
total_level_3_consumed_budget += consumed_budget\n total_level_3_consumed_budget += consumed_budget\n
total_level_3_available_budget += available_budget\n if available_budget:\n
total_level_3_available_budget += available_budget\n
\n \n
consumed_ratio = 0\n consumed_ratio = 0\n
if current_budget:\n if current_budget:\n
...@@ -302,11 +323,12 @@ for budget in budget_list:\n ...@@ -302,11 +323,12 @@ for budget in budget_list:\n
consumed_ratio=consumed_ratio))\n consumed_ratio=consumed_ratio))\n
\n \n
\n \n
total_level_2_initial_budget += total_level_3_initial_budget\n if is_higher_level3:\n
total_level_2_current_budget += total_level_3_current_budget\n total_level_2_initial_budget += total_level_3_initial_budget\n
total_level_2_engaged_budget += total_level_3_engaged_budget\n total_level_2_current_budget += total_level_3_current_budget\n
total_level_2_consumed_budget += total_level_3_consumed_budget\n total_level_2_engaged_budget += total_level_3_engaged_budget\n
total_level_2_available_budget += total_level_2_available_budget\n total_level_2_consumed_budget += total_level_3_consumed_budget\n
total_level_2_available_budget += total_level_2_available_budget\n
\n \n
if len(level_3_line_list) > 1 or level_4_category is None:\n if len(level_3_line_list) > 1 or level_4_category is None:\n
consumed_ratio = 0\n consumed_ratio = 0\n
...@@ -451,7 +473,11 @@ return pformat(line_list)\n ...@@ -451,7 +473,11 @@ return pformat(line_list)\n
<string>total_level_1_consumed_budget</string> <string>total_level_1_consumed_budget</string>
<string>total_level_1_available_budget</string> <string>total_level_1_available_budget</string>
<string>level_1_line_list</string> <string>level_1_line_list</string>
<string>consumed_budget_dict</string>
<string>engaged_budget_dict</string>
<string>budget_line_cell_range</string> <string>budget_line_cell_range</string>
<string>budget_line_as_cell_range_matrixbox</string>
<string>dependant_dimension_dict</string>
<string>len</string> <string>len</string>
<string>level_2_variation_category_list</string> <string>level_2_variation_category_list</string>
<string>level_3_variation_category_list</string> <string>level_3_variation_category_list</string>
...@@ -461,12 +487,10 @@ return pformat(line_list)\n ...@@ -461,12 +487,10 @@ return pformat(line_list)\n
<string>cell_style_dict</string> <string>cell_style_dict</string>
<string>cell_depth_dict</string> <string>cell_depth_dict</string>
<string>min_depth</string> <string>min_depth</string>
<string>budget_line_as_cell_range_matrixbox</string>
<string>cell_range_list</string> <string>cell_range_list</string>
<string>min</string> <string>min</string>
<string>_write_</string> <string>_write_</string>
<string>depth</string> <string>depth</string>
<string>higher_depth</string>
<string>sign</string> <string>sign</string>
<string>level_2_category</string> <string>level_2_category</string>
<string>total_level_2_initial_budget</string> <string>total_level_2_initial_budget</string>
...@@ -483,14 +507,15 @@ return pformat(line_list)\n ...@@ -483,14 +507,15 @@ return pformat(line_list)\n
<string>total_level_3_consumed_budget</string> <string>total_level_3_consumed_budget</string>
<string>total_level_3_available_budget</string> <string>total_level_3_available_budget</string>
<string>level_3_line_list</string> <string>level_3_line_list</string>
<string>is_higher_level3</string>
<string>level_4_category</string> <string>level_4_category</string>
<string>cell_key</string> <string>cell_key</string>
<string>consumed_budget</string>
<string>engaged_budget</string>
<string>_apply_</string> <string>_apply_</string>
<string>cell</string> <string>cell</string>
<string>initial_budget</string> <string>initial_budget</string>
<string>current_budget</string> <string>current_budget</string>
<string>engaged_budget</string>
<string>consumed_budget</string>
<string>available_budget</string> <string>available_budget</string>
<string>_inplacevar_</string> <string>_inplacevar_</string>
<string>consumed_ratio</string> <string>consumed_ratio</string>
......
315 316
\ No newline at end of file \ No newline at end of file
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