#7 New Form
* adds NewEcoAccountForm * refactors NewCompensationForm into AbstractCompensationForm so main fields can be reused again * fixes template bug in account detail view where the amount of deductions has been displayed instead of the available rest * refactors _generate_new_identifier() into generate_new_identifier() * refactors get_available_rest() into returning both, the total and relative amount * improves saving of SimpleGeometryForm() * adds/updates translations
This commit is contained in:
+14
-14
@@ -185,9 +185,9 @@ class Compensation(AbstractCompensation):
|
||||
def save(self, *args, **kwargs):
|
||||
if self.identifier is None or len(self.identifier) == 0:
|
||||
# Create new identifier
|
||||
new_id = self._generate_new_identifier()
|
||||
new_id = self.generate_new_identifier()
|
||||
while Compensation.objects.filter(identifier=new_id).exists():
|
||||
new_id = self._generate_new_identifier()
|
||||
new_id = self.generate_new_identifier()
|
||||
self.identifier = new_id
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@@ -322,9 +322,9 @@ class EcoAccount(AbstractCompensation):
|
||||
def save(self, *args, **kwargs):
|
||||
if self.identifier is None or len(self.identifier) == 0:
|
||||
# Create new identifier
|
||||
new_id = self._generate_new_identifier()
|
||||
new_id = self.generate_new_identifier()
|
||||
while EcoAccount.objects.filter(identifier=new_id).exists():
|
||||
new_id = self._generate_new_identifier()
|
||||
new_id = self.generate_new_identifier()
|
||||
self.identifier = new_id
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
@@ -355,28 +355,28 @@ class EcoAccount(AbstractCompensation):
|
||||
"""
|
||||
return self.after_states.all().aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
|
||||
def get_available_rest(self, as_percentage: bool = False) -> float:
|
||||
def get_available_rest(self) -> (float, float):
|
||||
""" Calculates available rest surface of the eco account
|
||||
|
||||
Args:
|
||||
as_percentage (bool): Whether to return the result as m² or %
|
||||
|
||||
Returns:
|
||||
|
||||
ret_val_total (float): Total amount
|
||||
ret_val_relative (float): Amount as percentage (0-100)
|
||||
"""
|
||||
deductions = self.deductions.filter(
|
||||
intervention__deleted=None,
|
||||
)
|
||||
deductions_surfaces = deductions.aggregate(Sum("surface"))["surface__sum"] or 0
|
||||
available_surfaces = self.deductable_surface or deductions_surfaces ## no division by zero
|
||||
ret_val = available_surfaces - deductions_surfaces
|
||||
ret_val_total = available_surfaces - deductions_surfaces
|
||||
|
||||
if as_percentage:
|
||||
if available_surfaces > 0:
|
||||
ret_val = int((ret_val / available_surfaces) * 100)
|
||||
else:
|
||||
ret_val = 0
|
||||
return ret_val
|
||||
if available_surfaces > 0:
|
||||
ret_val_relative = int((ret_val_total / available_surfaces) * 100)
|
||||
else:
|
||||
ret_val_relative = 0
|
||||
|
||||
return ret_val_total, ret_val_relative
|
||||
|
||||
def get_LANIS_link(self) -> str:
|
||||
""" Generates a link for LANIS depending on the geometry
|
||||
|
||||
Reference in New Issue
Block a user