|
|
@ -57,7 +57,7 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
|
|
|
|
|
|
|
|
|
|
|
def clean(self):
|
|
|
|
def clean(self):
|
|
|
|
# Deductable surface can not be larger than added states after surface
|
|
|
|
# Deductable surface can not be larger than added states after surface
|
|
|
|
after_state_sum = self.get_state_after_surface_sum()
|
|
|
|
after_state_sum = self.get_surface_after_states()
|
|
|
|
if self.deductable_surface > after_state_sum:
|
|
|
|
if self.deductable_surface > after_state_sum:
|
|
|
|
raise ValidationError(_("Deductable surface can not be larger than existing surfaces in after states"))
|
|
|
|
raise ValidationError(_("Deductable surface can not be larger than existing surfaces in after states"))
|
|
|
|
|
|
|
|
|
|
|
@ -96,15 +96,9 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
sum_surface (float)
|
|
|
|
sum_surface (float)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
return self.deductions.all().aggregate(Sum("surface"))["surface__sum"] or 0
|
|
|
|
val = self.deductions.all().aggregate(Sum("surface"))["surface__sum"] or 0
|
|
|
|
|
|
|
|
val = float('{:0.2f}'.format(val))
|
|
|
|
def get_state_after_surface_sum(self) -> float:
|
|
|
|
return val
|
|
|
|
""" Calculates the account's after state surface sum
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
|
|
|
sum_surface (float)
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
return self.after_states.all().aggregate(Sum("surface"))["surface__sum"] or 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def __calculate_deductable_rest(self):
|
|
|
|
def __calculate_deductable_rest(self):
|
|
|
|
""" Calculates available rest surface of the eco account
|
|
|
|
""" Calculates available rest surface of the eco account
|
|
|
@ -114,10 +108,7 @@ class EcoAccount(AbstractCompensation, ShareableObjectMixin, RecordableObjectMix
|
|
|
|
Returns:
|
|
|
|
Returns:
|
|
|
|
ret_val_total (float): Total amount
|
|
|
|
ret_val_total (float): Total amount
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
deductions = self.deductions.filter(
|
|
|
|
deductions_surfaces = self.get_deductions_surface()
|
|
|
|
intervention__deleted=None,
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
deductions_surfaces = deductions.aggregate(Sum("surface"))["surface__sum"] or 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
available_surface = self.deductable_surface
|
|
|
|
available_surface = self.deductable_surface
|
|
|
|
if available_surface is None:
|
|
|
|
if available_surface is None:
|
|
|
|