Withdraw to deduct
* refactors Models and attributes
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user