Withdraw to deduct
* refactors all files and variable names * WIP: Models and attributes
This commit is contained in:
+11
-11
@@ -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",
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user