EcoAccount withdraws

* adds functionality for withdraws from eco accounts in detail view of interventions and eco account as well
* adds get_surface() method to AbstractCompensation class to provide a simple getter for a sql calculation
* adds get_surface_withdraws() method to EcoAccount class to provide a simple getter for a sql calculation
* renames some routes to match coherent rout naming
* adds logic check on NewWithdrawForm
* renames templates/table directory to templates/form, since there are form-table templates inside --> more clarity
* adds new autocomplete routes to konova/urls.py for Interventions and EcoAccounts
* adds/updates translations
* adds/updates template comments
* updates requirements.txt
This commit is contained in:
mipel
2021-08-10 10:42:04 +02:00
parent 17d697da92
commit 72d61a23da
21 changed files with 388 additions and 121 deletions

View File

@@ -16,6 +16,7 @@ from django.shortcuts import render, get_object_or_404
from compensation.forms import NewStateModalForm, NewActionModalForm, NewDeadlineModalForm
from compensation.models import EcoAccount
from compensation.tables import EcoAccountTable
from intervention.forms import NewWithdrawForm
from konova.contexts import BaseContext
from konova.decorators import any_group_check, default_group_required
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm
@@ -94,8 +95,7 @@ def open_view(request: HttpRequest, id: str):
diff_states = abs(sum_before_states - sum_after_states)
# Calculate rest of available surface for withdraws
withdraws = acc.withdraws.all()
withdraw_surfaces = withdraws.aggregate(Sum("surface"))["surface__sum"] or 0
withdraw_surfaces = acc.get_surface_withdraws() or 0
available = int(((sum_after_states - withdraw_surfaces) / sum_after_states) * 100)
context = {
@@ -259,4 +259,24 @@ def new_document_view(request: HttpRequest, id: str):
return form.process_request(
request,
msg_success=_("Document added")
)
)
@login_required
@default_group_required
def new_withdraw_view(request: HttpRequest, id: str):
""" Renders a modal form view for creating withdraws
Args:
request ():
id ():
Returns:
"""
acc = get_object_or_404(EcoAccount, id=id)
form = NewWithdrawForm(request.POST or None, instance=acc, user=request.user)
return form.process_request(
request,
msg_success=_("Withdraw added")
)