Fix acc neg
This commit is contained in:
parent
cd64f20275
commit
db4ae73dfd
2 changed files with 7 additions and 2 deletions
|
@ -84,7 +84,7 @@ class Account(models.Model):
|
||||||
@property
|
@property
|
||||||
def real_balance(self):
|
def real_balance(self):
|
||||||
if (hasattr(self, 'negative')):
|
if (hasattr(self, 'negative')):
|
||||||
return self.balance + self.negative.balance_offset
|
return self.balance - self.negative.balance_offset
|
||||||
return self.balance
|
return self.balance
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
|
@ -354,6 +354,9 @@ def account_update(request, trigramme):
|
||||||
account_form = AccountForm(instance=account)
|
account_form = AccountForm(instance=account)
|
||||||
cof_form = CofRestrictForm(instance=account.cofprofile)
|
cof_form = CofRestrictForm(instance=account.cofprofile)
|
||||||
pwd_form = AccountPwdForm()
|
pwd_form = AccountPwdForm()
|
||||||
|
if account.balance < 0 and not hasattr(account, 'negative'):
|
||||||
|
AccountNegative.objects.create(account=account, start=timezone.now())
|
||||||
|
account.refresh_from_db()
|
||||||
if hasattr(account, 'negative'):
|
if hasattr(account, 'negative'):
|
||||||
negative_form = AccountNegativeForm(instance=account.negative)
|
negative_form = AccountNegativeForm(instance=account.negative)
|
||||||
else:
|
else:
|
||||||
|
@ -417,7 +420,7 @@ def account_update(request, trigramme):
|
||||||
balance_offset_new = negative_form.cleaned_data['balance_offset']
|
balance_offset_new = negative_form.cleaned_data['balance_offset']
|
||||||
if not balance_offset_new:
|
if not balance_offset_new:
|
||||||
balance_offset_new = 0
|
balance_offset_new = 0
|
||||||
balance_offset_diff = balance_offset_old - balance_offset_new
|
balance_offset_diff = balance_offset_new - balance_offset_old
|
||||||
Account.objects.filter(pk=account.pk).update(
|
Account.objects.filter(pk=account.pk).update(
|
||||||
balance = F('balance') + balance_offset_diff)
|
balance = F('balance') + balance_offset_diff)
|
||||||
negative_form.save()
|
negative_form.save()
|
||||||
|
@ -430,7 +433,9 @@ def account_update(request, trigramme):
|
||||||
|
|
||||||
if request.user == account.user:
|
if request.user == account.user:
|
||||||
missing_perm = False
|
missing_perm = False
|
||||||
|
account.refresh_from_db()
|
||||||
user_form = UserRestrictForm(request.POST, instance=account.user)
|
user_form = UserRestrictForm(request.POST, instance=account.user)
|
||||||
|
account_form = AccountRestrictForm(request.POST, instance=account)
|
||||||
|
|
||||||
if user_form.is_valid() and account_form.is_valid():
|
if user_form.is_valid() and account_form.is_valid():
|
||||||
user_form.save()
|
user_form.save()
|
||||||
|
|
Loading…
Reference in a new issue