Browse Source

fixed budget reporting in email

The reported available rest of the budget should be calculated via an excel formula. This lead to the warning in excel, that this file was downloaded from the internet and you need to accept this warning for the calculation to happen. With this fix, the rest of the budget is directly entered into the excel sheet.
pull/1/head
Holger Frey 5 years ago
parent
commit
da704c9943
  1. 34
      superx_budget/pyramid/overview.py
  2. 5
      superx_budget/pyramid/templates/overview.jinja2

34
superx_budget/pyramid/overview.py

@ -26,6 +26,22 @@ bei Fragen bitte an Holgi wenden @@ -26,6 +26,22 @@ bei Fragen bitte an Holgi wenden
"""
def _map_from_form_data(request, prefix):
if not prefix.endswith("-"):
prefix = f"{prefix}-"
result = {}
for key, value in request.POST.items():
if key.startswith(prefix):
row_str = key.split("-")[-1]
row = int(row_str)
try:
value = float(value)
except ValueError:
value = 0
result[row] = value
return result
@view_config(
context=Root,
request_method="GET",
@ -112,22 +128,17 @@ def send_overview(context, request): @@ -112,22 +128,17 @@ def send_overview(context, request):
recipients = tmp_recipients.splitlines()
budget_template = request.POST.get("template")
budget_file = request.budgets_dir / budget_template
expenses = {}
for key, value in request.POST.items():
if key.startswith("expense-"):
row_str = key.split("-")[-1]
row = int(row_str)
try:
value = float(value)
except ValueError:
value = 0
expenses[row] = value
budgets = _map_from_form_data(request, "budget-")
expenses = _map_from_form_data(request, "expense-")
available = {k: (v - expenses[k]) for k, v in budgets.items()}
# sanity check
if (
not export_date
or not recipients
or not expenses
or not available
or not budget_file.is_file()
):
request.session.flash(
@ -140,6 +151,9 @@ def send_overview(context, request): @@ -140,6 +151,9 @@ def send_overview(context, request):
for row, value in expenses.items():
cell = f"F{row}"
sheet[cell] = value
for row, value in available.items():
cell = f"G{row}"
sheet[cell] = value
budget_year = budget_file.stem.split("-")[-1]
message = Message(

5
superx_budget/pyramid/templates/overview.jinja2

@ -31,7 +31,10 @@ @@ -31,7 +31,10 @@
{{budget.budget_data.project_name}}
</td>
<td>{{budget.budget_data.project}}</td>
<td class="text-right">{{ "{:,.2f}".format(budget.budget_data.budget) }} €</td>
<td class="text-right">
<input type="hidden" name="budget-{{budget.row}}" value="{{ '{:.2f}'.format(budget.budget_data.budget) }}">
{{ "{:,.2f}".format(budget.budget_data.budget) }} €
</td>
<td class="text-right">
{% if budget.found %}
<input type="hidden" name="expense-{{budget.row}}" value="{{budget.expenses}}">

Loading…
Cancel
Save