diff --git a/kfet/forms.py b/kfet/forms.py
index f93ff068..4dd8a9bc 100644
--- a/kfet/forms.py
+++ b/kfet/forms.py
@@ -150,7 +150,6 @@ class AccountNegativeForm(forms.ModelForm):
fields = [
"authz_overdraft_amount",
"authz_overdraft_until",
- "balance_offset",
"comment",
]
widgets = {"authz_overdraft_until": DateTimeWidget()}
diff --git a/kfet/migrations/0075_remove_accountnegative_balance_offset.py b/kfet/migrations/0075_remove_accountnegative_balance_offset.py
new file mode 100644
index 00000000..bf06e9ae
--- /dev/null
+++ b/kfet/migrations/0075_remove_accountnegative_balance_offset.py
@@ -0,0 +1,17 @@
+# Generated by Django 2.2.17 on 2021-02-23 21:40
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("kfet", "0074_auto_20210219_1337"),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name="accountnegative",
+ name="balance_offset",
+ ),
+ ]
diff --git a/kfet/models.py b/kfet/models.py
index 622c0ac9..7156ae52 100644
--- a/kfet/models.py
+++ b/kfet/models.py
@@ -129,12 +129,6 @@ class Account(models.Model):
def balance_ukf(self):
return to_ukf(self.balance, is_cof=self.is_cof)
- @property
- def real_balance(self):
- if hasattr(self, "negative") and self.negative.balance_offset:
- return self.balance - self.negative.balance_offset
- return self.balance
-
@property
def name(self):
return self.user.get_full_name()
@@ -275,7 +269,7 @@ class Account(models.Model):
self.password = hash_password(clear_password)
def update_negative(self):
- if self.real_balance < 0:
+ if self.balance < 0:
if hasattr(self, "negative") and not self.negative.start:
self.negative.start = timezone.now()
self.negative.save()
@@ -284,15 +278,8 @@ class Account(models.Model):
account=self, start=timezone.now()
)
elif hasattr(self, "negative"):
- # self.real_balance >= 0
- balance_offset = self.negative.balance_offset
- if balance_offset:
- (
- Account.objects.filter(pk=self.pk).update(
- balance=F("balance") - balance_offset
- )
- )
- self.refresh_from_db()
+ # self.balance >= 0
+ # TODO: méchanisme pour éviter de contourner le délai de négatif ?
self.negative.delete()
class UserHasAccount(Exception):
@@ -318,15 +305,6 @@ class AccountNegative(models.Model):
Account, on_delete=models.CASCADE, related_name="negative"
)
start = models.DateTimeField(blank=True, null=True, default=None)
- balance_offset = models.DecimalField(
- "décalage de balance",
- help_text="Montant non compris dans l'autorisation de négatif",
- max_digits=6,
- decimal_places=2,
- blank=True,
- null=True,
- default=None,
- )
authz_overdraft_amount = models.DecimalField(
"négatif autorisé",
max_digits=6,
diff --git a/kfet/templates/kfet/account_negative.html b/kfet/templates/kfet/account_negative.html
index fa8b508d..9ca9cd99 100644
--- a/kfet/templates/kfet/account_negative.html
+++ b/kfet/templates/kfet/account_negative.html
@@ -35,20 +35,16 @@
{% block main %}
-
+
Tri. |
Nom |
Balance |
- Réelle |
Début |
Découvert autorisé |
Jusqu'au |
- Balance offset |
@@ -61,11 +57,6 @@
{{ neg.account.name }} |
{{ neg.account.balance|floatformat:2 }}€ |
-
- {% if neg.balance_offset %}
- {{ neg.account.real_balance|floatformat:2 }}€
- {% endif %}
- |
{{ neg.start|date:'d/m/Y H:i'}}
|
@@ -73,11 +64,10 @@
{{ neg.authz_overdraft_until|date:'d/m/Y H:i' }}
|
- {{ neg.balance_offset|default_if_none:'' }} |
{% endfor %}
-{% endblock %}
+{% endblock %}
\ No newline at end of file
diff --git a/kfet/templates/kfet/left_account.html b/kfet/templates/kfet/left_account.html
index 716c96cc..a058abf9 100644
--- a/kfet/templates/kfet/left_account.html
+++ b/kfet/templates/kfet/left_account.html
@@ -39,7 +39,8 @@
{{ account.departement }} {{ account.promo }}
{% if account.is_cof %}
- Adhérent COF
+ Adhérent COF
{% else %}
Non-COF
{% endif %}
@@ -54,9 +55,6 @@
{% if account.negative.start %}
Depuis le {{ account.negative.start|date:"d/m/Y à H:i" }}
{% endif %}
- {% if account.real_balance != account.balance %}
- Solde réel: {{ account.real_balance }} €
- {% endif %}
Plafond :
{{ account.negative.authz_overdraft_amount|default:kfet_config.overdraft_amount }} €
@@ -89,20 +87,20 @@
{% endif %}
+ });
+
\ No newline at end of file
diff --git a/kfet/views.py b/kfet/views.py
index 0fe99ea4..5322082c 100644
--- a/kfet/views.py
+++ b/kfet/views.py
@@ -396,29 +396,12 @@ def account_update(request, trigramme):
if request.user.has_perm("kfet.manage_perms") and group_form.is_valid():
group_form.save()
- # Checking perm to manage negative
- if hasattr(account, "negative"):
- balance_offset_old = 0
- if account.negative.balance_offset:
- balance_offset_old = account.negative.balance_offset
if (
hasattr(account, "negative")
and request.user.has_perm("kfet.change_accountnegative")
and negative_form.is_valid()
):
- balance_offset_new = negative_form.cleaned_data["balance_offset"]
- if not balance_offset_new:
- balance_offset_new = 0
- balance_offset_diff = balance_offset_new - balance_offset_old
- Account.objects.filter(pk=account.pk).update(
- balance=F("balance") + balance_offset_diff
- )
negative_form.save()
- if (
- Account.objects.get(pk=account.pk).balance >= 0
- and not balance_offset_new
- ):
- AccountNegative.objects.get(account=account).delete()
success = True
messages.success(
@@ -513,8 +496,8 @@ class AccountNegativeList(ListView):
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
- real_balances = (neg.account.real_balance for neg in self.object_list)
- context["negatives_sum"] = sum(real_balances)
+ balances = (neg.account.balance for neg in self.object_list)
+ context["negatives_sum"] = sum(balances)
return context
@@ -1716,16 +1699,7 @@ def perform_transfers(request):
balance=F("balance") + to_accounts_balances[account]
)
account.refresh_from_db()
- if account.balance < 0:
- if hasattr(account, "negative"):
- if not account.negative.start:
- account.negative.start = timezone.now()
- account.negative.save()
- else:
- negative = AccountNegative(account=account, start=timezone.now())
- negative.save()
- elif hasattr(account, "negative") and not account.negative.balance_offset:
- account.negative.delete()
+ account.update_negative()
# Saving transfer group
transfergroup.save()
@@ -1827,16 +1801,7 @@ def cancel_transfers(request):
balance=F("balance") + to_accounts_balances[account]
)
account.refresh_from_db()
- if account.balance < 0:
- if hasattr(account, "negative"):
- if not account.negative.start:
- account.negative.start = timezone.now()
- account.negative.save()
- else:
- negative = AccountNegative(account=account, start=timezone.now())
- negative.save()
- elif hasattr(account, "negative") and not account.negative.balance_offset:
- account.negative.delete()
+ account.update_negative()
transfers = (
Transfer.objects.values("id", "canceled_at", "canceled_by__trigramme")