Withdraw to deduct

* refactors all files and variable names
* WIP: Models and attributes
This commit is contained in:
mipel
2021-08-30 11:29:15 +02:00
parent 3ab9081fe0
commit 3f6f576095
15 changed files with 117 additions and 117 deletions

View File

@@ -451,8 +451,8 @@ class RunCheckForm(BaseModalForm):
)
class NewWithdrawForm(BaseModalForm):
""" Form for creating new withdraws
class NewDeductionForm(BaseModalForm):
""" Form for creating new deduction
Can be used for Intervention view as well as for EcoAccount views.
@@ -463,7 +463,7 @@ class NewWithdrawForm(BaseModalForm):
account = forms.ModelChoiceField(
label=_("Eco-account"),
label_suffix="",
help_text=_("Only recorded accounts can be selected for withdraws"),
help_text=_("Only recorded accounts can be selected for deductions"),
queryset=EcoAccount.objects.filter(deleted=None),
widget=autocomplete.ModelSelect2(
url="accounts-autocomplete",
@@ -497,8 +497,8 @@ class NewWithdrawForm(BaseModalForm):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.form_title = _("New Withdraw")
self.form_caption = _("Enter the information for a new withdraw from a chosen eco-account")
self.form_title = _("New Deduction")
self.form_caption = _("Enter the information for a new deduction from a chosen eco-account")
self.is_intervention_initially = False
# Add a placeholder for field 'surface' without having to define the whole widget above
@@ -520,7 +520,7 @@ class NewWithdrawForm(BaseModalForm):
def is_valid(self):
""" Custom validity check
Makes sure the withdraw can not contain more surface than the account still provides
Makes sure the deduction can not contain more surface than the account still provides
Returns:
is_valid (bool)
@@ -534,20 +534,20 @@ class NewWithdrawForm(BaseModalForm):
if not acc.recorded:
self.add_error(
"account",
_("Eco-account {} is not recorded yet. You can only withdraw from recorded accounts.").format(acc.identifier)
_("Eco-account {} is not recorded yet. You can only deduct from recorded accounts.").format(acc.identifier)
)
return False
# Calculate valid surface
sum_surface = acc.get_surface()
sum_surface_withdraws = acc.get_surface_withdraws()
rest_surface = sum_surface - sum_surface_withdraws
sum_surface_deductions = acc.get_deductions_surface()
rest_surface = sum_surface - sum_surface_deductions
form_surface = float(self.cleaned_data["surface"])
is_valid_surface = form_surface < rest_surface
if not is_valid_surface:
self.add_error(
"surface",
_("The account {} has not enough surface for a withdraw of {} m². There are only {} m² left").format(acc.identifier, form_surface, rest_surface),
_("The account {} has not enough surface for a deduction of {} m². There are only {} m² left").format(acc.identifier, form_surface, rest_surface),
)
return is_valid_surface and super_result
@@ -566,19 +566,19 @@ class NewWithdrawForm(BaseModalForm):
self.instance.modified = user_action_edit
self.instance.save()
# Create withdraw depending on Intervention or EcoAccount as the initial instance
# Create deductions depending on Intervention or EcoAccount as the initial instance
if self.is_intervention_initially:
withdraw = EcoAccountWithdraw.objects.create(
deduction = EcoAccountWithdraw.objects.create(
intervention=self.instance,
account=self.cleaned_data["account"],
surface=self.cleaned_data["surface"],
created=user_action_create,
)
else:
withdraw = EcoAccountWithdraw.objects.create(
deduction = EcoAccountWithdraw.objects.create(
intervention=self.cleaned_data["intervention"],
account=self.instance,
surface=self.cleaned_data["surface"],
created=user_action_create,
)
return withdraw
return deduction

View File

@@ -1,17 +1,17 @@
{% load i18n l10n fontawesome_5 humanize %}
<div id="eco-account-withdraws" class="card">
<div id="eco-account-deductions" class="card">
<div class="card-header rlp-r">
<div class="row">
<div class="col-sm-6">
<h5>
<span class="badge badge-light">{{intervention.withdraws.count}}</span>
{% trans 'Eco Account Withdraws' %}
{% trans 'Eco Account Deductions' %}
</h5>
</div>
<div class="col-sm-6">
<div class="d-flex justify-content-end">
{% if is_default_member and has_access %}
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'intervention:acc-new-withdraw' intervention.id %}" title="{% trans 'Add new withdraw' %}">
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'intervention:acc-new-deduction' intervention.id %}" title="{% trans 'Add new deduction' %}">
{% fa5_icon 'plus' %}
{% fa5_icon 'tree' %}
</button>
@@ -39,21 +39,21 @@
</tr>
</thead>
<tbody>
{% for withdraw in intervention.withdraws.all %}
<tr {% if withdraw.account.deleted %}class="align-middle alert-danger" title="{% trans 'Eco-account deleted! Withdraw invalid!' %}" {% elif not withdraw.account.recorded %}class="align-middle alert-danger" title="{% trans 'Eco-account not recorded! Withdraw invalid!' %}" {% endif %}>
{% for deduction in intervention.withdraws.all %}
<tr {% if deduction.account.deleted %}class="align-middle alert-danger" title="{% trans 'Eco-account deleted! Deduction invalid!' %}" {% elif not deduction.account.recorded %}class="align-middle alert-danger" title="{% trans 'Eco-account not recorded! Deduction invalid!' %}" {% endif %}>
<td class="align-middle">
<a href="{% url 'compensation:acc-open' withdraw.account.id %}">
{% if withdraw.account.deleted or not withdraw.account.recorded %}
<a href="{% url 'compensation:acc-open' deduction.account.id %}">
{% if deduction.account.deleted or not deduction.account.recorded %}
{% fa5_icon 'exclamation-triangle' %}
{% endif %}
{{ withdraw.account.identifier }}
{{ deduction.account.identifier }}
</a>
</td>
<td class="align-middle">{{ withdraw.surface|floatformat:2|intcomma }} m²</td>
<td class="align-middle">{{ withdraw.created.timestamp|default_if_none:""|naturalday}}</td>
<td class="align-middle">{{ deduction.surface|floatformat:2|intcomma }} m²</td>
<td class="align-middle">{{ deduction.created.timestamp|default_if_none:""|naturalday}}</td>
<td>
{% if is_default_member and has_access %}
<button data-form-url="{% url 'compensation:withdraw-remove' withdraw.account.id withdraw.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove Withdraw' %}">
<button data-form-url="{% url 'compensation:deduction-remove' deduction.account.id deduction.id %}" class="btn btn-default btn-modal" title="{% trans 'Remove Deduction' %}">
{% fa5_icon 'trash' %}
</button>
{% endif %}

View File

@@ -133,7 +133,7 @@
</div>
<div class="row">
<div class="col-sm-12 col-md-12 col-lg-6">
{% include 'intervention/detail/includes/withdraws.html' %}
{% include 'intervention/detail/includes/deductions.html' %}
</div>
<div class="col-sm-12 col-md-12 col-lg-6">
{% include 'intervention/detail/includes/revocation.html' %}

View File

@@ -8,7 +8,7 @@ Created on: 30.11.20
from django.urls import path
from intervention.views import index_view, new_view, open_view, edit_view, remove_view, new_document_view, share_view, \
create_share_view, remove_revocation_view, new_revocation_view, run_check_view, log_view, new_withdraw_view, \
create_share_view, remove_revocation_view, new_revocation_view, run_check_view, log_view, new_deduction_view, \
record_view
app_name = "intervention"
@@ -25,8 +25,8 @@ urlpatterns = [
path('<id>/check', run_check_view, name='run-check'),
path('<id>/record', record_view, name='record'),
# Withdraws
path('<id>/withdraw/new', new_withdraw_view, name='acc-new-withdraw'),
# Deductions
path('<id>/deduction/new', new_deduction_view, name='acc-new-deduction'),
# Revocation routes
path('<id>/revocation/new', new_revocation_view, name='new-revocation'),

View File

@@ -5,7 +5,7 @@ from django.http import HttpRequest
from django.shortcuts import render, get_object_or_404
from intervention.forms import NewInterventionForm, EditInterventionForm, ShareInterventionForm, NewRevocationForm, \
RunCheckForm, NewWithdrawForm
RunCheckForm, NewDeductionForm
from intervention.models import Intervention, Revocation
from intervention.tables import InterventionTable
from konova.contexts import BaseContext
@@ -341,21 +341,21 @@ def log_view(request: HttpRequest, id: str):
@login_required
@default_group_required
def new_withdraw_view(request: HttpRequest, id: str):
""" Renders a modal form view for creating withdraws
def new_deduction_view(request: HttpRequest, id: str):
""" Renders a modal form view for creating deductions
Args:
request (HttpRequest): The incoming request
id (str): The intervention's id which shall get a new withdraw
id (str): The intervention's id which shall benefit from this deduction
Returns:
"""
intervention = get_object_or_404(Intervention, id=id)
form = NewWithdrawForm(request.POST or None, instance=intervention, user=request.user)
form = NewDeductionForm(request.POST or None, instance=intervention, user=request.user)
return form.process_request(
request,
msg_success=_("Withdraw added")
msg_success=_("Deduction added")
)