From 13785fd5201dab3ae4babe57084950616d66fb4c Mon Sep 17 00:00:00 2001 From: Skia Date: Tue, 20 Dec 2016 23:27:54 +0100 Subject: [PATCH] Prevent users that have never subscribed to subscribe on Eboutic --- counter/models.py | 61 ++++++++++++++++++++++++----------------------- eboutic/views.py | 2 ++ sith/settings.py | 1 + 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/counter/models.py b/counter/models.py index eb1680c2..38a1acfe 100644 --- a/counter/models.py +++ b/counter/models.py @@ -346,36 +346,37 @@ class Selling(models.Model): self.customer.amount -= self.quantity * self.unit_price self.customer.save() self.is_validated = True - if self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER: - s = User.objects.filter(id=self.customer.user.id).first() - sub = Subscription( - member=s, - subscription_type='un-semestre', - payment_method="EBOUTIC", - location="EBOUTIC", - ) - sub.subscription_start = Subscription.compute_start() - sub.subscription_start = Subscription.compute_start( - duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration']) - sub.subscription_end = Subscription.compute_end( - duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration'], - start=sub.subscription_start) - sub.save() - elif self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_TWO_SEMESTERS: - s = User.objects.filter(id=self.customer.user.id).first() - sub = Subscription( - member=s, - subscription_type='deux-semestres', - payment_method="EBOUTIC", - location="EBOUTIC", - ) - sub.subscription_start = Subscription.compute_start() - sub.subscription_start = Subscription.compute_start( - duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration']) - sub.subscription_end = Subscription.compute_end( - duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration'], - start=sub.subscription_start) - sub.save() + u = User.objects.filter(id=self.customer.user.id).first() + if u.was_subscribed(): + if self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER: + sub = Subscription( + member=u, + subscription_type='un-semestre', + payment_method="EBOUTIC", + location="EBOUTIC", + ) + sub.subscription_start = Subscription.compute_start() + sub.subscription_start = Subscription.compute_start( + duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration']) + sub.subscription_end = Subscription.compute_end( + duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration'], + start=sub.subscription_start) + sub.save() + elif self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_TWO_SEMESTERS: + u = User.objects.filter(id=self.customer.user.id).first() + sub = Subscription( + member=u, + subscription_type='deux-semestres', + payment_method="EBOUTIC", + location="EBOUTIC", + ) + sub.subscription_start = Subscription.compute_start() + sub.subscription_start = Subscription.compute_start( + duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration']) + sub.subscription_end = Subscription.compute_end( + duration=settings.SITH_SUBSCRIPTIONS[sub.subscription_type]['duration'], + start=sub.subscription_start) + sub.save() try: if self.product.eticket: self.send_mail_customer() diff --git a/eboutic/views.py b/eboutic/views.py index 7241955b..e2de3201 100644 --- a/eboutic/views.py +++ b/eboutic/views.py @@ -78,6 +78,8 @@ class EbouticMain(TemplateView): kwargs['basket'] = self.basket kwargs['eboutic'] = Counter.objects.filter(type="EBOUTIC").first() kwargs['categories'] = ProductType.objects.all() + if not self.request.user.was_subscribed(): + kwargs['categories'] = kwargs['categories'].exclude(id=settings.SITH_PRODUCTTYPE_SUBSCRIPTION) return kwargs class EbouticCommand(TemplateView): diff --git a/sith/settings.py b/sith/settings.py index 549d739f..ca838a39 100644 --- a/sith/settings.py +++ b/sith/settings.py @@ -332,6 +332,7 @@ SITH_COUNTER_PRODUCTTYPE_REFILLING = 11 # Defines which product is the one year subscription and which one is the six month subscription SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER = 93 SITH_PRODUCT_SUBSCRIPTION_TWO_SEMESTERS = 94 +SITH_PRODUCTTYPE_SUBSCRIPTION = 23 # Subscription durations are in semestres # Be careful, modifying this parameter will need a migration to be applied