Commit d0beda5f authored by Gabriel Detraz's avatar Gabriel Detraz

Gère le cas pas d'objet sac

parent d21485a7
...@@ -5,7 +5,6 @@ from django import forms ...@@ -5,7 +5,6 @@ from django import forms
from django.db.models.signals import post_save, post_delete from django.db.models.signals import post_save, post_delete
from django.dispatch import receiver from django.dispatch import receiver
from amap.settings import RIGHTS_LINK, REQ_EXPIRE_HRS from amap.settings import RIGHTS_LINK, REQ_EXPIRE_HRS
import re, uuid import re, uuid
import datetime import datetime
...@@ -13,7 +12,7 @@ import datetime ...@@ -13,7 +12,7 @@ import datetime
from django.utils import timezone from django.utils import timezone
from django.contrib.auth.models import AbstractBaseUser, BaseUserManager from django.contrib.auth.models import AbstractBaseUser, BaseUserManager
from panier.models import Credit, Commande from panier.models import Credit, Commande, Panier
def get_admin_right(): def get_admin_right():
try: try:
...@@ -153,8 +152,13 @@ class User(AbstractBaseUser): ...@@ -153,8 +152,13 @@ class User(AbstractBaseUser):
def solde(self): def solde(self):
""" Renvoie le solde dynamiquement""" """ Renvoie le solde dynamiquement"""
try:
sac_prix = Panier.objects.get(nom="Sac").prix
except Panier.DoesNotExist:
# Pass silencieusement si l'objet n'existe pas
sac_prix = 1
credit = sum(credit.montant for credit in Credit.objects.filter(user=self) if credit.validite) credit = sum(credit.montant for credit in Credit.objects.filter(user=self) if credit.validite)
debit = sum(commande.prix_unitaire*commande.quantite for commande in Commande.objects.filter(user=self)) + self.sac_consignes debit = sum(commande.prix_unitaire*commande.quantite for commande in Commande.objects.filter(user=self)) + self.sac_consignes*sac_prix
return credit-debit return credit-debit
def __str__(self): def __str__(self):
......
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