Commit 7a267dbc authored by Skia's avatar Skia 🤘
Browse files

Create the customer when subscribing if it does not exists yet

parent 97ff4341
Pipeline #59 failed with stage
in 1 minute and 4 seconds
...@@ -5,6 +5,7 @@ from django.conf import settings ...@@ -5,6 +5,7 @@ from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from datetime import timedelta from datetime import timedelta
from random import randrange
from club.models import Club from club.models import Club
from accounting.models import CurrencyField from accounting.models import CurrencyField
...@@ -27,6 +28,9 @@ class Customer(models.Model): ...@@ -27,6 +28,9 @@ class Customer(models.Model):
def __str__(self): def __str__(self):
return self.user.username return self.user.username
def generate_account_id():
return randrange(0, 4000) # TODO: improve me!
class ProductType(models.Model): class ProductType(models.Model):
""" """
This describes a product type This describes a product type
......
...@@ -35,10 +35,7 @@ class Subscription(models.Model): ...@@ -35,10 +35,7 @@ class Subscription(models.Model):
# TODO add location! # TODO add location!
class Meta: class Meta:
permissions = ( ordering = ['subscription_start',]
('change_subscription', 'Can make someone become a subscriber'),
('view_subscription', 'Can view who is a subscriber'),
)
def clean(self): def clean(self):
try: try:
...@@ -50,8 +47,11 @@ class Subscription(models.Model): ...@@ -50,8 +47,11 @@ class Subscription(models.Model):
# TODO see SubscriptionForm's clean method # TODO see SubscriptionForm's clean method
raise ValidationError(_("You are trying to create a subscription without member")) raise ValidationError(_("You are trying to create a subscription without member"))
class Meta: def save(self):
ordering = ['subscription_start',] super(Subscription, self).save()
from counter.models import Customer
if not Customer.objects.filter(user=self.member).exists():
Customer(user=self.member, account_id=Customer.generate_account_id(), amount=0).save()
def get_absolute_url(self): def get_absolute_url(self):
return reverse('core:user_profile', kwargs={'user_id': self.member.pk}) return reverse('core:user_profile', kwargs={'user_id': self.member.pk})
......
Supports Markdown
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