diff --git a/compensation/admin.py b/compensation/admin.py index f4bfed2..4d14858 100644 --- a/compensation/admin.py +++ b/compensation/admin.py @@ -1,7 +1,7 @@ from django.contrib import admin from compensation.models import Compensation, CompensationAction, CompensationState, Payment, \ - EcoAccountWithdraw, EcoAccount + EcoAccountDeduction, EcoAccount class CompensationStateAdmin(admin.ModelAdmin): @@ -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, EcoAccountDeductionAdmin) +admin.site.register(EcoAccountDeduction, EcoAccountDeductionAdmin) diff --git a/compensation/models.py b/compensation/models.py index 6278c7b..556f100 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -238,7 +238,7 @@ class EcoAccount(AbstractCompensation): Returns: sum_surface (float) """ - return self.withdraws.all().aggregate(Sum("surface"))["surface__sum"] or 0 + return self.deductions.all().aggregate(Sum("surface"))["surface__sum"] or 0 def get_available_rest(self, as_percentage: bool = False): """ Calculates available rest surface of the eco account @@ -250,7 +250,7 @@ class EcoAccount(AbstractCompensation): """ ret_val = 0 - deductions = self.withdraws.filter( + deductions = self.deductions.filter( intervention__deleted=None, ) deductions_surfaces = deductions.aggregate(Sum("surface"))["surface__sum"] or 0 @@ -299,7 +299,7 @@ class EcoAccount(AbstractCompensation): return ret_msgs -class EcoAccountWithdraw(BaseResource): +class EcoAccountDeduction(BaseResource): """ A deduction object for eco accounts """ @@ -309,7 +309,7 @@ class EcoAccountWithdraw(BaseResource): null=True, blank=True, help_text="Deducted from", - related_name="withdraws", + related_name="deductions", ) surface = models.FloatField( null=True, @@ -325,7 +325,7 @@ class EcoAccountWithdraw(BaseResource): null=True, blank=True, help_text="Deducted for", - related_name="withdraws", + related_name="deductions", ) def __str__(self): diff --git a/compensation/views/eco_account_views.py b/compensation/views/eco_account_views.py index c73a8c5..86677ff 100644 --- a/compensation/views/eco_account_views.py +++ b/compensation/views/eco_account_views.py @@ -97,7 +97,7 @@ def open_view(request: HttpRequest, id: str): # Calculate rest of available surface for deductions available = acc.get_available_rest(as_percentage=True) - deductions = acc.withdraws.filter( + deductions = acc.deductions.filter( intervention__deleted=None, ) @@ -156,7 +156,7 @@ def deduction_remove_view(request: HttpRequest, id: str, deduction_id: str): """ acc = get_object_or_404(EcoAccount, id=id) try: - eco_deduction = acc.withdraws.get(id=deduction_id) + eco_deduction = acc.deductions.get(id=deduction_id) except ObjectDoesNotExist: raise Http404("Unknown deduction") diff --git a/intervention/forms.py b/intervention/forms.py index 0c22ec5..25ff7d3 100644 --- a/intervention/forms.py +++ b/intervention/forms.py @@ -14,7 +14,7 @@ from django.db import transaction from django.urls import reverse from django.utils.translation import gettext_lazy as _ -from compensation.models import EcoAccountWithdraw, EcoAccount +from compensation.models import EcoAccountDeduction, EcoAccount from intervention.models import Intervention, Revocation from konova.forms import BaseForm, BaseModalForm from konova.models import Document @@ -568,14 +568,14 @@ class NewDeductionForm(BaseModalForm): # Create deductions depending on Intervention or EcoAccount as the initial instance if self.is_intervention_initially: - deduction = EcoAccountWithdraw.objects.create( + deduction = EcoAccountDeduction.objects.create( intervention=self.instance, account=self.cleaned_data["account"], surface=self.cleaned_data["surface"], created=user_action_create, ) else: - deduction = EcoAccountWithdraw.objects.create( + deduction = EcoAccountDeduction.objects.create( intervention=self.cleaned_data["intervention"], account=self.instance, surface=self.cleaned_data["surface"], diff --git a/intervention/templates/intervention/detail/includes/deductions.html b/intervention/templates/intervention/detail/includes/deductions.html index c9f1fba..bfbfa36 100644 --- a/intervention/templates/intervention/detail/includes/deductions.html +++ b/intervention/templates/intervention/detail/includes/deductions.html @@ -4,7 +4,7 @@
- {{intervention.withdraws.count}} + {{intervention.deductions.count}} {% trans 'Eco Account Deductions' %}
@@ -39,7 +39,7 @@ - {% for deduction in intervention.withdraws.all %} + {% for deduction in intervention.deductions.all %}