Commit 5a7f24d5 authored by Hamza Dely's avatar Hamza Dely

Élimine des résidus de code référençant des modèles supprimés

parent f09cb57d
......@@ -29,8 +29,8 @@ class BoutonConsoForm(forms.Form):
transaction = Transaction.objects.create(
emetteur=emetteur,
destinataire=bouton.credite,
action=Action.objects.get(action="vente"),
moyen=Paiement.objects.get(moyen="note"),
action=Transaction.VENTE,
moyen=Transaction.NOTE,
quantite=self.cleaned_data['quantite'],
montant=bouton.montant,
description=bouton.etiquette,
......@@ -49,19 +49,19 @@ class CreditConsoForm(forms.Form):
"""
destinataires = forms.ModelMultipleChoiceField(queryset=Note.objects.order_by('adherent_id').exclude(adherent__supprime=True))
montant = forms.DecimalField(max_digits=14, decimal_places=2, required=True)
moyen = forms.ModelChoiceField(queryset=Paiement.objects.exclude(moyen="note"))
moyen = forms.ChoiceField(choices=MOYENS_DE_PAIEMENT_CONSOS)
def save(self, commit=True):
for destinataire in self.cleaned_data['destinataires']:
transaction = Transaction.objects.create(
emetteur=None,
destinataire=destinataire,
action=Action.objects.get(action="crédit"),
action=Transaction.CREDIT,
moyen=self.cleaned_data['moyen'],
quantite=1,
montant=self.cleaned_data['montant'],
description="Crédit %s" % self.cleaned_data['moyen'],
categorie=Categorie.objects.get(nom="gestion"),
categorie="Opération de gestion",
valide=True,
)
destinataire.solde = F('solde') + transaction.montant
......@@ -73,23 +73,23 @@ class RetraitConsoForm(forms.Form):
"""
emetteurs = forms.ModelMultipleChoiceField(queryset=Note.objects.order_by('adherent_id').exclude(adherent__supprime=True))
montant = forms.DecimalField(max_digits=14, decimal_places=2, required=True)
moyen = forms.ModelChoiceField(queryset=Paiement.objects.exclude(moyen="note"))
moyen = forms.ChoiceField(choices=MOYENS_DE_PAIEMENT_CONSOS)
def save(self, commit=True):
for emetteur in self.cleaned_data['emetteurs']:
transaction = Transaction.objects.create(
emetteur=emetteur,
destinataire=None,
action=Action.objects.get(action="retrait"),
action=Transaction.RETRAIT,
moyen=self.cleaned_data['moyen'],
quantite=1,
montant=self.cleaned_data['montant'],
description="Retrait %s" % self.cleaned_data['moyen'],
categorie=Categorie.objects.get(nom="gestion"),
categorie="Opération de gestion",
valide=True,
)
destinataire.solde = F('solde') + transaction.montant
destinataire.save()
emetteur.solde = F('solde') + transaction.montant
emetteur.save()
class TransfertConsoForm(forms.Form):
"""
......@@ -105,12 +105,12 @@ class TransfertConsoForm(forms.Form):
transaction = Transaction.objects.create(
emetteur=emetteur,
destinataire=destinataire,
action=Action.objects.get(action="transfert"),
moyen=Paiement.objects.get(moyen="note"),
action=Transaction.TRANSFERT,
moyen=Transaction.NOTE,
quantite=1,
montant=self.cleaned_data['montant'],
description="Transfert : %s" % self.cleaned_data['description'],
categorie=Categorie.objects.get(nom="gestion"),
categorie="Opération de gestion",
valide=True,
)
emetteur.solde = F('solde') - transaction.montant
......
# -*- coding: utf-8 -*-
# Generated by Django 1.11.14 on 2018-08-25 14:03
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('consos', '0002_auto_20180823_2147'),
]
operations = [
migrations.AlterField(
model_name='bouton',
name='etiquette',
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name='transaction',
name='action',
field=models.CharField(choices=[('vente', 'vente'), ('crédit', 'crédit'), ('retrait', 'retrait'), ('transfert', 'transfert')], max_length=255),
),
migrations.AlterUniqueTogether(
name='bouton',
unique_together=set([('etiquette', 'categorie')]),
),
]
......@@ -4,7 +4,7 @@
from datetime import timedelta
from django.db import models
from django.db import models, transaction
from django.core.exceptions import ValidationError
def releve_freq_validator(value):
......@@ -95,11 +95,13 @@ class Transaction(models.Model):
]
## Actions
VENTE = "vente"
CREDIT = "crédit"
RETRAIT = "retrait"
TRANSFERT = "transfert"
ACTIONS = [
(VENTE, VENTE),
(CREDIT, CREDIT),
(RETRAIT, RETRAIT),
(TRANSFERT, TRANSFERT),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment