Withdraw to deduct
* refactors all files and variable names * WIP: Models and attributes
This commit is contained in:
+14
-14
@@ -451,8 +451,8 @@ class RunCheckForm(BaseModalForm):
|
||||
)
|
||||
|
||||
|
||||
class NewWithdrawForm(BaseModalForm):
|
||||
""" Form for creating new withdraws
|
||||
class NewDeductionForm(BaseModalForm):
|
||||
""" Form for creating new deduction
|
||||
|
||||
Can be used for Intervention view as well as for EcoAccount views.
|
||||
|
||||
@@ -463,7 +463,7 @@ class NewWithdrawForm(BaseModalForm):
|
||||
account = forms.ModelChoiceField(
|
||||
label=_("Eco-account"),
|
||||
label_suffix="",
|
||||
help_text=_("Only recorded accounts can be selected for withdraws"),
|
||||
help_text=_("Only recorded accounts can be selected for deductions"),
|
||||
queryset=EcoAccount.objects.filter(deleted=None),
|
||||
widget=autocomplete.ModelSelect2(
|
||||
url="accounts-autocomplete",
|
||||
@@ -497,8 +497,8 @@ class NewWithdrawForm(BaseModalForm):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.form_title = _("New Withdraw")
|
||||
self.form_caption = _("Enter the information for a new withdraw from a chosen eco-account")
|
||||
self.form_title = _("New Deduction")
|
||||
self.form_caption = _("Enter the information for a new deduction from a chosen eco-account")
|
||||
self.is_intervention_initially = False
|
||||
|
||||
# Add a placeholder for field 'surface' without having to define the whole widget above
|
||||
@@ -520,7 +520,7 @@ class NewWithdrawForm(BaseModalForm):
|
||||
def is_valid(self):
|
||||
""" Custom validity check
|
||||
|
||||
Makes sure the withdraw can not contain more surface than the account still provides
|
||||
Makes sure the deduction can not contain more surface than the account still provides
|
||||
|
||||
Returns:
|
||||
is_valid (bool)
|
||||
@@ -534,20 +534,20 @@ class NewWithdrawForm(BaseModalForm):
|
||||
if not acc.recorded:
|
||||
self.add_error(
|
||||
"account",
|
||||
_("Eco-account {} is not recorded yet. You can only withdraw from recorded accounts.").format(acc.identifier)
|
||||
_("Eco-account {} is not recorded yet. You can only deduct from recorded accounts.").format(acc.identifier)
|
||||
)
|
||||
return False
|
||||
|
||||
# Calculate valid surface
|
||||
sum_surface = acc.get_surface()
|
||||
sum_surface_withdraws = acc.get_surface_withdraws()
|
||||
rest_surface = sum_surface - sum_surface_withdraws
|
||||
sum_surface_deductions = acc.get_deductions_surface()
|
||||
rest_surface = sum_surface - sum_surface_deductions
|
||||
form_surface = float(self.cleaned_data["surface"])
|
||||
is_valid_surface = form_surface < rest_surface
|
||||
if not is_valid_surface:
|
||||
self.add_error(
|
||||
"surface",
|
||||
_("The account {} has not enough surface for a withdraw of {} m². There are only {} m² left").format(acc.identifier, form_surface, rest_surface),
|
||||
_("The account {} has not enough surface for a deduction of {} m². There are only {} m² left").format(acc.identifier, form_surface, rest_surface),
|
||||
)
|
||||
return is_valid_surface and super_result
|
||||
|
||||
@@ -566,19 +566,19 @@ class NewWithdrawForm(BaseModalForm):
|
||||
self.instance.modified = user_action_edit
|
||||
self.instance.save()
|
||||
|
||||
# Create withdraw depending on Intervention or EcoAccount as the initial instance
|
||||
# Create deductions depending on Intervention or EcoAccount as the initial instance
|
||||
if self.is_intervention_initially:
|
||||
withdraw = EcoAccountWithdraw.objects.create(
|
||||
deduction = EcoAccountWithdraw.objects.create(
|
||||
intervention=self.instance,
|
||||
account=self.cleaned_data["account"],
|
||||
surface=self.cleaned_data["surface"],
|
||||
created=user_action_create,
|
||||
)
|
||||
else:
|
||||
withdraw = EcoAccountWithdraw.objects.create(
|
||||
deduction = EcoAccountWithdraw.objects.create(
|
||||
intervention=self.cleaned_data["intervention"],
|
||||
account=self.instance,
|
||||
surface=self.cleaned_data["surface"],
|
||||
created=user_action_create,
|
||||
)
|
||||
return withdraw
|
||||
return deduction
|
||||
Reference in New Issue
Block a user