From fdb105ab84cc39a12cbe66a1c668eda285b14f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Delobelle?= Date: Sat, 6 Aug 2016 23:59:44 +0200 Subject: [PATCH] =?UTF-8?q?V=C3=A9rification=20suppl=C3=A9mentaire=20sur?= =?UTF-8?q?=20K-Psul?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Ajout d'une exception Checkout.IsProtected - Rend impossible d'utiliser une caisse (Checkout) protégée (is_protected) dans K-Psul Une caisse protégée est, par exemple, la caisse qui recevra les rechargements par CB en ligne. --- kfet/models.py | 3 +++ kfet/views.py | 4 +++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/kfet/models.py b/kfet/models.py index 0e3af79b..ff69d0fa 100644 --- a/kfet/models.py +++ b/kfet/models.py @@ -186,6 +186,9 @@ class Checkout(models.Model): class Meta: ordering = ['-valid_to'] + class IsProtected(Exception): + pass + def __str__(self): return self.name diff --git a/kfet/views.py b/kfet/views.py index 6f478d7d..529e6053 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -397,7 +397,9 @@ def kpsul_perform_operations(request): try: checkout_pk = request.POST.get('checkout', 0) checkout = Checkout.objects.get(pk=checkout_pk) - except (Checkout.DoesNotExist, ValueError): + if checkout.is_protected: + raise Checkout.IsProtected + except (Checkout.DoesNotExist, ValueError, Checkout.IsProtected): data['errors'].append('Caisse invalide') if 'errors' in data: return JsonResponse(data, status=400)