Withdraw to deduct
* refactors Models and attributes
This commit is contained in:
		
							parent
							
								
									cd5fb9cad6
								
							
						
					
					
						commit
						d569be80b3
					
				@ -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")
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -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"],
 | 
			
		||||
 | 
			
		||||
@ -4,7 +4,7 @@
 | 
			
		||||
        <div class="row">
 | 
			
		||||
            <div class="col-sm-6">
 | 
			
		||||
                <h5>
 | 
			
		||||
                    <span class="badge badge-light">{{intervention.withdraws.count}}</span>
 | 
			
		||||
                    <span class="badge badge-light">{{intervention.deductions.count}}</span>
 | 
			
		||||
                    {% trans 'Eco Account Deductions' %}
 | 
			
		||||
                </h5>
 | 
			
		||||
            </div>
 | 
			
		||||
@ -39,7 +39,7 @@
 | 
			
		||||
            </tr>
 | 
			
		||||
            </thead>
 | 
			
		||||
            <tbody>
 | 
			
		||||
            {% for deduction in intervention.withdraws.all %}
 | 
			
		||||
            {% for deduction in intervention.deductions.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' deduction.account.id %}">
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user