Withdraw to deduct
* refactors all files and variable names * WIP: Models and attributes
This commit is contained in:
@@ -24,8 +24,8 @@ urlpatterns = [
|
||||
# Document remove route can be found in konova/urls.py
|
||||
path('<id>/document/new/', new_document_view, name='acc-new-doc'),
|
||||
|
||||
# Eco-account withdraws
|
||||
path('<id>/remove/<withdraw_id>', withdraw_remove_view, name='withdraw-remove'),
|
||||
path('<id>/withdraw/new', new_withdraw_view, name='acc-new-withdraw'),
|
||||
# Eco-account deductions
|
||||
path('<id>/remove/<deduction_id>', deduction_remove_view, name='deduction-remove'),
|
||||
path('<id>/deduct/new', new_deduction_view, name='acc-new-deduction'),
|
||||
|
||||
]
|
||||
@@ -47,7 +47,7 @@ class PaymentAdmin(admin.ModelAdmin):
|
||||
]
|
||||
|
||||
|
||||
class EcoAccountWithdrawAdmin(admin.ModelAdmin):
|
||||
class EcoAccountDeductionAdmin(admin.ModelAdmin):
|
||||
list_display = [
|
||||
"id",
|
||||
"account",
|
||||
@@ -61,4 +61,4 @@ admin.site.register(Payment, PaymentAdmin)
|
||||
admin.site.register(CompensationAction, CompensationActionAdmin)
|
||||
admin.site.register(CompensationState, CompensationStateAdmin)
|
||||
admin.site.register(EcoAccount, EcoAccountAdmin)
|
||||
admin.site.register(EcoAccountWithdraw, EcoAccountWithdrawAdmin)
|
||||
admin.site.register(EcoAccountWithdraw, EcoAccountDeductionAdmin)
|
||||
|
||||
@@ -201,7 +201,7 @@ class Compensation(AbstractCompensation):
|
||||
class EcoAccount(AbstractCompensation):
|
||||
"""
|
||||
An eco account is a kind of 'prepaid' compensation. It can be compared to an account that already has been filled
|
||||
with some kind of currency. From this account one is able to 'withdraw' currency for current projects.
|
||||
with some kind of currency. From this account one is able to deduct currency for current projects.
|
||||
"""
|
||||
# Users having access on this object
|
||||
# Not needed in regular Compensation since their access is defined by the linked intervention's access
|
||||
@@ -232,8 +232,8 @@ class EcoAccount(AbstractCompensation):
|
||||
self.identifier = new_id
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_surface_withdraws(self) -> float:
|
||||
""" Calculates the compensation's/account's surface
|
||||
def get_deductions_surface(self) -> float:
|
||||
""" Calculates the account's deductions sum surface
|
||||
|
||||
Returns:
|
||||
sum_surface (float)
|
||||
@@ -250,12 +250,12 @@ class EcoAccount(AbstractCompensation):
|
||||
|
||||
"""
|
||||
ret_val = 0
|
||||
withdraws = self.withdraws.filter(
|
||||
deductions = self.withdraws.filter(
|
||||
intervention__deleted=None,
|
||||
)
|
||||
withdraw_surfaces = withdraws.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
after_states_surfaces = self.after_states.all().aggregate(Sum("surface"))["surface__sum"] or withdraw_surfaces ## no division by zero
|
||||
ret_val = after_states_surfaces - withdraw_surfaces
|
||||
deductions_surfaces = deductions.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
after_states_surfaces = self.after_states.all().aggregate(Sum("surface"))["surface__sum"] or deductions_surfaces ## no division by zero
|
||||
ret_val = after_states_surfaces - deductions_surfaces
|
||||
|
||||
if as_percentage:
|
||||
if after_states_surfaces > 0:
|
||||
@@ -301,20 +301,20 @@ class EcoAccount(AbstractCompensation):
|
||||
|
||||
class EcoAccountWithdraw(BaseResource):
|
||||
"""
|
||||
A withdraw object for eco accounts
|
||||
A deduction object for eco accounts
|
||||
"""
|
||||
account = models.ForeignKey(
|
||||
EcoAccount,
|
||||
on_delete=models.SET_NULL,
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Withdrawn from",
|
||||
help_text="Deducted from",
|
||||
related_name="withdraws",
|
||||
)
|
||||
surface = models.FloatField(
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Amount withdrawn (m²)",
|
||||
help_text="Amount deducted (m²)",
|
||||
validators=[
|
||||
MinValueValidator(limit_value=0.00),
|
||||
]
|
||||
@@ -324,7 +324,7 @@ class EcoAccountWithdraw(BaseResource):
|
||||
on_delete=models.CASCADE,
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Withdrawn for",
|
||||
help_text="Deducted for",
|
||||
related_name="withdraws",
|
||||
)
|
||||
|
||||
|
||||
@@ -252,7 +252,7 @@ class EcoAccountTable(BaseTable):
|
||||
"""
|
||||
html = ""
|
||||
checked = value is not None
|
||||
tooltip = _("Not recorded yet. Can not be used for withdraws, yet.")
|
||||
tooltip = _("Not recorded yet. Can not be used for deductions, yet.")
|
||||
if checked:
|
||||
value = value.timestamp
|
||||
value = localtime(value)
|
||||
|
||||
@@ -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">{{withdraws.count}}</span>
|
||||
{% trans 'Eco Account Withdraws' %}
|
||||
<span class="badge badge-light">{{deductions.count}}</span>
|
||||
{% 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 'compensation:acc-new-withdraw' obj.id %}" title="{% trans 'Add new withdraw' %}">
|
||||
<button class="btn btn-outline-default btn-modal" data-form-url="{% url 'compensation:acc-new-deduction' obj.id %}" title="{% trans 'Add new deduction' %}">
|
||||
{% fa5_icon 'plus' %}
|
||||
{% fa5_icon 'tree' %}
|
||||
</button>
|
||||
@@ -42,25 +42,25 @@
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for withdraw in withdraws %}
|
||||
{% for deduction in deductions %}
|
||||
<tr>
|
||||
<td class="align-middle">
|
||||
<a href="{% url 'intervention:open' withdraw.intervention.id %}">
|
||||
{{ withdraw.intervention.identifier }}
|
||||
<a href="{% url 'intervention:open' deduction.intervention.id %}">
|
||||
{{ deduction.intervention.identifier }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="align-middle">
|
||||
{% if withdraw.intervention.recorded %}
|
||||
<em title='{{ withdraw.intervention.recorded_tooltip }}' class='fas fa-bookmark registered-bookmark'></em>
|
||||
{% if deduction.intervention.recorded %}
|
||||
<em title='{{ deduction.intervention.recorded_tooltip }}' class='fas fa-bookmark registered-bookmark'></em>
|
||||
{% else %}
|
||||
<em title='{{ withdraw.intervention.recorded_tooltip }}' class='far fa-bookmark'></em>
|
||||
<em title='{{ deduction.intervention.recorded_tooltip }}' class='far fa-bookmark'></em>
|
||||
{% endif %}
|
||||
</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 %}
|
||||
@@ -110,7 +110,7 @@
|
||||
{% include 'compensation/detail/eco_account/includes/documents.html' %}
|
||||
</div>
|
||||
<div class="col-sm-12 col-md-12 col-lg-6">
|
||||
{% include 'compensation/detail/eco_account/includes/withdraws.html' %}
|
||||
{% include 'compensation/detail/eco_account/includes/deductions.html' %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -16,7 +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 intervention.forms import NewDeductionForm
|
||||
from konova.contexts import BaseContext
|
||||
from konova.decorators import any_group_check, default_group_required, conservation_office_group_required
|
||||
from konova.forms import RemoveModalForm, SimpleGeomForm, NewDocumentForm, RecordModalForm
|
||||
@@ -94,10 +94,10 @@ def open_view(request: HttpRequest, id: str):
|
||||
sum_after_states = after_states.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
diff_states = abs(sum_before_states - sum_after_states)
|
||||
|
||||
# Calculate rest of available surface for withdraws
|
||||
# Calculate rest of available surface for deductions
|
||||
available = acc.get_available_rest(as_percentage=True)
|
||||
|
||||
withdraws = acc.withdraws.filter(
|
||||
deductions = acc.withdraws.filter(
|
||||
intervention__deleted=None,
|
||||
)
|
||||
|
||||
@@ -115,7 +115,7 @@ def open_view(request: HttpRequest, id: str):
|
||||
"is_zb_member": in_group(_user, ZB_GROUP),
|
||||
"is_ets_member": in_group(_user, ETS_GROUP),
|
||||
"LANIS_LINK": acc.get_LANIS_link(),
|
||||
"withdraws": withdraws,
|
||||
"deductions": deductions,
|
||||
}
|
||||
context = BaseContext(request, context).context
|
||||
return render(request, template, context)
|
||||
@@ -143,27 +143,27 @@ def remove_view(request: HttpRequest, id: str):
|
||||
|
||||
@login_required
|
||||
@default_group_required
|
||||
def withdraw_remove_view(request: HttpRequest, id: str, withdraw_id: str):
|
||||
""" Renders a modal view for removing withdraws
|
||||
def deduction_remove_view(request: HttpRequest, id: str, deduction_id: str):
|
||||
""" Renders a modal view for removing deductions
|
||||
|
||||
Args:
|
||||
request (HttpRequest): The incoming request
|
||||
id (str): The eco account's id
|
||||
withdraw_id (str): The withdraw's id
|
||||
deduction_id (str): The deduction's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
try:
|
||||
eco_withdraw = acc.withdraws.get(id=withdraw_id)
|
||||
eco_deduction = acc.withdraws.get(id=deduction_id)
|
||||
except ObjectDoesNotExist:
|
||||
raise Http404("Unknown withdraw")
|
||||
raise Http404("Unknown deduction")
|
||||
|
||||
form = RemoveModalForm(request.POST or None, instance=eco_withdraw, user=request.user)
|
||||
form = RemoveModalForm(request.POST or None, instance=eco_deduction, user=request.user)
|
||||
return form.process_request(
|
||||
request=request,
|
||||
msg_success=_("Withdraw removed")
|
||||
msg_success=_("Deduction removed")
|
||||
)
|
||||
|
||||
|
||||
@@ -291,19 +291,19 @@ def new_document_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 ():
|
||||
id ():
|
||||
request (HttpRequest): THe incoming request
|
||||
id (str): The eco account's id
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
acc = get_object_or_404(EcoAccount, id=id)
|
||||
form = NewWithdrawForm(request.POST or None, instance=acc, user=request.user)
|
||||
form = NewDeductionForm(request.POST or None, instance=acc, user=request.user)
|
||||
return form.process_request(
|
||||
request,
|
||||
msg_success=_("Withdraw added")
|
||||
msg_success=_("Deduction added")
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user