Commit 28431ec9 authored by Skia's avatar Skia 🤘
Browse files

Big refactor: remove Subscriber class

parent 0d4b6970
Pipeline #490 passed with stage
in 2 minutes and 31 seconds
...@@ -8,7 +8,6 @@ from django.core.urlresolvers import reverse ...@@ -8,7 +8,6 @@ from django.core.urlresolvers import reverse
from django.utils import timezone from django.utils import timezone
from core.models import User, MetaGroup, Group, SithFile from core.models import User, MetaGroup, Group, SithFile
from subscription.models import Subscriber
# Create your models here. # Create your models here.
...@@ -120,7 +119,7 @@ class Club(models.Model): ...@@ -120,7 +119,7 @@ class Club(models.Model):
""" """
Method to see if that object can be seen by the given user Method to see if that object can be seen by the given user
""" """
sub = Subscriber.objects.filter(pk=user.pk).first() sub = User.objects.filter(pk=user.pk).first()
if sub is None: if sub is None:
return False return False
return sub.is_subscribed() return sub.is_subscribed()
...@@ -151,7 +150,7 @@ class Membership(models.Model): ...@@ -151,7 +150,7 @@ class Membership(models.Model):
description = models.CharField(_('description'), max_length=128, null=False, blank=True) description = models.CharField(_('description'), max_length=128, null=False, blank=True)
def clean(self): def clean(self):
sub = Subscriber.objects.filter(pk=self.user.pk).first() sub = User.objects.filter(pk=self.user.pk).first()
if sub is None or not sub.is_subscribed(): if sub is None or not sub.is_subscribed():
raise ValidationError(_('User must be subscriber to take part to a club')) raise ValidationError(_('User must be subscriber to take part to a club'))
if Membership.objects.filter(user=self.user).filter(club=self.club).filter(end_date=None).exists(): if Membership.objects.filter(user=self.user).filter(club=self.club).filter(end_date=None).exists():
......
...@@ -12,7 +12,7 @@ from django.contrib.sites.models import Site ...@@ -12,7 +12,7 @@ from django.contrib.sites.models import Site
from core.models import Group, User, Page, PageRev, SithFile from core.models import Group, User, Page, PageRev, SithFile
from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType, Company from accounting.models import GeneralJournal, BankAccount, ClubAccount, Operation, AccountingType, Company
from club.models import Club, Membership from club.models import Club, Membership
from subscription.models import Subscription, Subscriber from subscription.models import Subscription
from counter.models import Customer, ProductType, Product, Counter from counter.models import Customer, ProductType, Product, Counter
class Command(BaseCommand): class Command(BaseCommand):
...@@ -201,7 +201,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -201,7 +201,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
# Subscription # Subscription
## Root ## Root
s = Subscription(member=Subscriber.objects.filter(pk=root.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=root.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
...@@ -209,7 +209,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -209,7 +209,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Skia ## Skia
s = Subscription(member=Subscriber.objects.filter(pk=skia.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=skia.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
...@@ -217,7 +217,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -217,7 +217,7 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Comptable ## Comptable
s = Subscription(member=Subscriber.objects.filter(pk=comptable.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=comptable.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
...@@ -225,15 +225,15 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site. ...@@ -225,15 +225,15 @@ Cette page vise à documenter la syntaxe *Markdown* utilisée sur le site.
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Richard ## Richard
s = Subscription(member=Subscriber.objects.filter(pk=r.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=r.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'], duration=settings.SITH_SUBSCRIPTIONS[s.subscription_type]['duration'],
start=s.subscription_start) start=s.subscription_start)
s.save() s.save()
## Subscriber ## User
s = Subscription(member=Subscriber.objects.filter(pk=subscriber.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0], s = Subscription(member=User.objects.filter(pk=subscriber.pk).first(), subscription_type=list(settings.SITH_SUBSCRIPTIONS.keys())[0],
payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0]) payment_method=settings.SITH_SUBSCRIPTION_PAYMENT_METHOD[0])
s.subscription_start = s.compute_start() s.subscription_start = s.compute_start()
s.subscription_end = s.compute_end( s.subscription_end = s.compute_end(
......
...@@ -195,6 +195,10 @@ class User(AbstractBaseUser): ...@@ -195,6 +195,10 @@ class User(AbstractBaseUser):
def to_dict(self): def to_dict(self):
return self.__dict__ return self.__dict__
def is_subscribed(self):
s = self.subscriptions.last()
return s.is_valid_now() if s is not None else False
def is_in_group(self, group_name): def is_in_group(self, group_name):
"""If the user is in the group passed in argument (as string or by id)""" """If the user is in the group passed in argument (as string or by id)"""
group_id = 0 group_id = 0
...@@ -208,15 +212,7 @@ class User(AbstractBaseUser): ...@@ -208,15 +212,7 @@ class User(AbstractBaseUser):
if group_id == settings.SITH_GROUP_PUBLIC_ID: if group_id == settings.SITH_GROUP_PUBLIC_ID:
return True return True
if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked if group_name == settings.SITH_MAIN_MEMBERS_GROUP: # We check the subscription if asked
if 'subscription' in settings.INSTALLED_APPS: return self.is_subscribed()
from subscription.models import Subscriber
s = Subscriber.objects.filter(pk=self.pk).first()
if s is not None and s.is_subscribed():
return True
else:
return False
else:
return False
if group_name[-len(settings.SITH_BOARD_SUFFIX):] == settings.SITH_BOARD_SUFFIX: if group_name[-len(settings.SITH_BOARD_SUFFIX):] == settings.SITH_BOARD_SUFFIX:
from club.models import Club from club.models import Club
name = group_name[:-len(settings.SITH_BOARD_SUFFIX)] name = group_name[:-len(settings.SITH_BOARD_SUFFIX)]
......
...@@ -35,15 +35,15 @@ ...@@ -35,15 +35,15 @@
{%- endmacro %} {%- endmacro %}
{% macro user_subscription(user) %} {% macro user_subscription(user) %}
{% trans subscription_end=get_subscriber(user).subscriptions.last().subscription_end %}Subscribed until {{ subscription_end }}{% endtrans %}<br/> {% trans subscription_end=user.subscriptions.last().subscription_end %}Subscribed until {{ subscription_end }}{% endtrans %}<br/>
{% trans %}Account number: {% endtrans %}{{ user.customer.account_id }}<br/> {% trans %}Account number: {% endtrans %}{{ user.customer.account_id }}<br/>
{%- endmacro %} {%- endmacro %}
{% macro show_slots(user) %} {% macro show_slots(user) %}
{% if get_subscriber(user).slots.filter(start_date__gte=timezone.now()).exists() %} {% if user.slots.filter(start_date__gte=timezone.now()).exists() %}
<h5>{% trans %}Slot{% endtrans %}</h5> <h5>{% trans %}Slot{% endtrans %}</h5>
<ul> <ul>
{% for i in get_subscriber(user).slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %} {% for i in user.slots.filter(start_date__gte=timezone.now().replace(tzinfo=None)).all() %}
<li>{{ i.get_type_display() }} - {{i.machine.launderette }}, {{ i.start_date|date("l j") }} : {{ i.start_date|time(DATETIME_FORMAT) }}</li> <li>{{ i.get_type_display() }} - {{i.machine.launderette }}, {{ i.start_date|date("l j") }} : {{ i.start_date|time(DATETIME_FORMAT) }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
...@@ -51,10 +51,10 @@ ...@@ -51,10 +51,10 @@
{% endmacro %} {% endmacro %}
{% macro show_tokens(user) %} {% macro show_tokens(user) %}
{% if get_subscriber(user).tokens.exists() %} {% if user.tokens.exists() %}
<h5>{% trans %}Tokens{% endtrans %}</h5> <h5>{% trans %}Tokens{% endtrans %}</h5>
<ul> <ul>
{% for i in get_subscriber(user).tokens.all() %} {% for i in user.tokens.all() %}
<li>{{ i }}</li> <li>{{ i }}</li>
{% endfor %} {% endfor %}
</ul> </ul>
...@@ -65,4 +65,4 @@ ...@@ -65,4 +65,4 @@
{% if user == profile or user.is_root or user.is_board_member %} {% if user == profile or user.is_root or user.is_board_member %}
<a href="{{ url("core:user_godfathers_delete", user_id=profile.id, godfather_id=godfather.id, is_father=is_father) }}">{% trans %}Delete{% endtrans %}</a> <a href="{{ url("core:user_godfathers_delete", user_id=profile.id, godfather_id=godfather.id, is_father=is_father) }}">{% trans %}Delete{% endtrans %}</a>
{% endif %} {% endif %}
{% endmacro %} {% endmacro %}
\ No newline at end of file
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
{% if user.memberships.filter(end_date=None).exists() or user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user == profile %} {% if user.memberships.filter(end_date=None).exists() or user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or user == profile %}
{# if the user is member of a club, he can view the subscription state #} {# if the user is member of a club, he can view the subscription state #}
<p> <p>
{% if get_subscriber(profile).is_subscribed() %} {% if profile.is_subscribed() %}
{% if user == profile or user.is_root or user.is_board_member %} {% if user == profile or user.is_root or user.is_board_member %}
{{ user_subscription(profile) }} {{ user_subscription(profile) }}
{% endif %} {% endif %}
......
...@@ -139,7 +139,7 @@ class Migration(migrations.Migration): ...@@ -139,7 +139,7 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='counter', model_name='counter',
name='sellers', name='sellers',
field=models.ManyToManyField(related_name='counters', to='subscription.Subscriber', blank=True, verbose_name='sellers'), field=models.ManyToManyField(related_name='counters', to='core.User', blank=True, verbose_name='sellers'),
), ),
migrations.AddField( migrations.AddField(
model_name='counter', model_name='counter',
......
...@@ -16,8 +16,7 @@ import datetime ...@@ -16,8 +16,7 @@ import datetime
from club.models import Club from club.models import Club
from accounting.models import CurrencyField from accounting.models import CurrencyField
from core.models import Group, User, Notification from core.models import Group, User, Notification
from subscription.models import Subscriber, Subscription from subscription.models import Subscription
from subscription.views import get_subscriber
class Customer(models.Model): class Customer(models.Model):
""" """
...@@ -134,7 +133,7 @@ class Counter(models.Model): ...@@ -134,7 +133,7 @@ class Counter(models.Model):
type = models.CharField(_('counter type'), type = models.CharField(_('counter type'),
max_length=255, max_length=255,
choices=[('BAR',_('Bar')), ('OFFICE',_('Office')), ('EBOUTIC',_('Eboutic'))]) choices=[('BAR',_('Bar')), ('OFFICE',_('Office')), ('EBOUTIC',_('Eboutic'))])
sellers = models.ManyToManyField(Subscriber, verbose_name=_('sellers'), related_name='counters', blank=True) sellers = models.ManyToManyField(User, verbose_name=_('sellers'), related_name='counters', blank=True)
edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True) edit_groups = models.ManyToManyField(Group, related_name="editable_counters", blank=True)
view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True) view_groups = models.ManyToManyField(Group, related_name="viewable_counters", blank=True)
token = models.CharField(_('token'), max_length=30, null=True, blank=True) token = models.CharField(_('token'), max_length=30, null=True, blank=True)
...@@ -164,7 +163,7 @@ class Counter(models.Model): ...@@ -164,7 +163,7 @@ class Counter(models.Model):
def can_be_viewed_by(self, user): def can_be_viewed_by(self, user):
if self.type == "BAR" or self.type == "EBOUTIC": if self.type == "BAR" or self.type == "EBOUTIC":
return True return True
sub = get_subscriber(request.user) sub = request.user
return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or sub in self.sellers return user.is_in_group(settings.SITH_MAIN_BOARD_GROUP) or sub in self.sellers
  • Maintainer

    Je suis pas trop sûr, mais je pense qu'il y a un petit soucis par ici

  • Author Maintainer

    ah bon?

  • Maintainer

    Alors oui mais non, ça a été réglé quand on a mis à jour les settings de la prod. Tout va bien ici du coup

Please register or sign in to reply
def gen_token(self): def gen_token(self):
...@@ -349,7 +348,7 @@ class Selling(models.Model): ...@@ -349,7 +348,7 @@ class Selling(models.Model):
self.customer.save() self.customer.save()
self.is_validated = True self.is_validated = True
if self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER: if self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_ONE_SEMESTER:
s = Subscriber.objects.filter(id=self.customer.user.id).first() s = User.objects.filter(id=self.customer.user.id).first()
sub = Subscription( sub = Subscription(
member=s, member=s,
subscription_type='un-semestre', subscription_type='un-semestre',
...@@ -364,7 +363,7 @@ class Selling(models.Model): ...@@ -364,7 +363,7 @@ class Selling(models.Model):
start=sub.subscription_start) start=sub.subscription_start)
sub.save() sub.save()
elif self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_TWO_SEMESTERS: elif self.product and self.product.id == settings.SITH_PRODUCT_SUBSCRIPTION_TWO_SEMESTERS:
s = Subscriber.objects.filter(id=self.customer.user.id).first() s = User.objects.filter(id=self.customer.user.id).first()
sub = Subscription( sub = Subscription(
member=s, member=s,
subscription_type='deux-semestres', subscription_type='deux-semestres',
......
...@@ -22,8 +22,7 @@ from ajax_select import make_ajax_form, make_ajax_field ...@@ -22,8 +22,7 @@ from ajax_select import make_ajax_form, make_ajax_field
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin, TabedViewMixin
from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime from core.views.forms import SelectUser, LoginForm, SelectDate, SelectDateTime
from core.models import User from core.models import User
from subscription.models import Subscriber, Subscription from subscription.models import Subscription
from subscription.views import get_subscriber
from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, CashRegisterSummary, CashRegisterSummaryItem, Eticket from counter.models import Counter, Customer, Product, Selling, Refilling, ProductType, CashRegisterSummary, CashRegisterSummaryItem, Eticket
from accounting.models import CurrencyField from accounting.models import CurrencyField
...@@ -49,7 +48,7 @@ class GetUserForm(forms.Form): ...@@ -49,7 +48,7 @@ class GetUserForm(forms.Form):
cus = Customer.objects.filter(account_id__iexact=cleaned_data['code']).first() cus = Customer.objects.filter(account_id__iexact=cleaned_data['code']).first()
elif cleaned_data['id'] is not None: elif cleaned_data['id'] is not None:
cus = Customer.objects.filter(user=cleaned_data['id']).first() cus = Customer.objects.filter(user=cleaned_data['id']).first()
sub = get_subscriber(cus.user) if cus is not None else None sub = cus.user if cus is not None else None
if (cus is None or sub is None or not sub.subscriptions.last() or if (cus is None or sub is None or not sub.subscriptions.last() or
(date.today() - sub.subscriptions.last().subscription_end) > timedelta(days=90)): (date.today() - sub.subscriptions.last().subscription_end) > timedelta(days=90)):
raise forms.ValidationError(_("User not found")) raise forms.ValidationError(_("User not found"))
......
...@@ -5,7 +5,7 @@ from django.conf import settings ...@@ -5,7 +5,7 @@ from django.conf import settings
from accounting.models import CurrencyField from accounting.models import CurrencyField
from counter.models import Counter, Product, Customer, Selling, Refilling from counter.models import Counter, Product, Customer, Selling, Refilling
from core.models import User from core.models import User
from subscription.models import Subscription, Subscriber from subscription.models import Subscription
class Basket(models.Model): class Basket(models.Model):
""" """
......
...@@ -57,7 +57,7 @@ class Migration(migrations.Migration): ...@@ -57,7 +57,7 @@ class Migration(migrations.Migration):
('type', models.CharField(choices=[('WASHING', 'Washing'), ('DRYING', 'Drying')], max_length=10, verbose_name='type')), ('type', models.CharField(choices=[('WASHING', 'Washing'), ('DRYING', 'Drying')], max_length=10, verbose_name='type')),
('borrow_date', models.DateTimeField(null=True, verbose_name='borrow date', blank=True)), ('borrow_date', models.DateTimeField(null=True, verbose_name='borrow date', blank=True)),
('launderette', models.ForeignKey(verbose_name='launderette', to='launderette.Launderette', related_name='tokens')), ('launderette', models.ForeignKey(verbose_name='launderette', to='launderette.Launderette', related_name='tokens')),
('user', models.ForeignKey(null=True, related_name='tokens', verbose_name='user', to='subscription.Subscriber', blank=True)), ('user', models.ForeignKey(null=True, related_name='tokens', verbose_name='user', to='core.User', blank=True)),
], ],
options={ options={
'verbose_name': 'Token', 'verbose_name': 'Token',
...@@ -72,7 +72,7 @@ class Migration(migrations.Migration): ...@@ -72,7 +72,7 @@ class Migration(migrations.Migration):
migrations.AddField( migrations.AddField(
model_name='slot', model_name='slot',
name='user', name='user',
field=models.ForeignKey(verbose_name='user', to='subscription.Subscriber', related_name='slots'), field=models.ForeignKey(verbose_name='user', to='core.User', related_name='slots'),
), ),
migrations.AlterUniqueTogether( migrations.AlterUniqueTogether(
name='token', name='token',
......
...@@ -5,8 +5,6 @@ from django.core.urlresolvers import reverse ...@@ -5,8 +5,6 @@ from django.core.urlresolvers import reverse
from counter.models import Counter, Product from counter.models import Counter, Product
from core.models import User from core.models import User
from subscription.models import Subscriber
from subscription.views import get_subscriber
from club.models import Club from club.models import Club
# Create your models here. # Create your models here.
...@@ -86,7 +84,7 @@ class Token(models.Model): ...@@ -86,7 +84,7 @@ class Token(models.Model):
launderette = models.ForeignKey(Launderette, related_name='tokens', verbose_name=_('launderette')) launderette = models.ForeignKey(Launderette, related_name='tokens', verbose_name=_('launderette'))
type = models.CharField(_('type'), max_length=10, choices=settings.SITH_LAUNDERETTE_MACHINE_TYPES) type = models.CharField(_('type'), max_length=10, choices=settings.SITH_LAUNDERETTE_MACHINE_TYPES)
borrow_date = models.DateTimeField(_('borrow date'), null=True, blank=True) borrow_date = models.DateTimeField(_('borrow date'), null=True, blank=True)
user = models.ForeignKey(Subscriber, related_name='tokens', verbose_name=_('user'), null=True, blank=True) user = models.ForeignKey(User, related_name='tokens', verbose_name=_('user'), null=True, blank=True)
class Meta: class Meta:
verbose_name = _('Token') verbose_name = _('Token')
...@@ -123,7 +121,7 @@ class Slot(models.Model): ...@@ -123,7 +121,7 @@ class Slot(models.Model):
type = models.CharField(_('type'), max_length=10, choices=settings.SITH_LAUNDERETTE_MACHINE_TYPES) type = models.CharField(_('type'), max_length=10, choices=settings.SITH_LAUNDERETTE_MACHINE_TYPES)
machine = models.ForeignKey(Machine, related_name='slots', verbose_name=_('machine')) machine = models.ForeignKey(Machine, related_name='slots', verbose_name=_('machine'))
token = models.ForeignKey(Token, related_name='slots', verbose_name=_('token'), blank=True, null=True) token = models.ForeignKey(Token, related_name='slots', verbose_name=_('token'), blank=True, null=True)
user = models.ForeignKey(Subscriber, related_name='slots', verbose_name=_('user')) user = models.ForeignKey(User, related_name='slots', verbose_name=_('user'))
class Meta: class Meta:
verbose_name = _('Slot') verbose_name = _('Slot')
......
...@@ -20,8 +20,6 @@ from core.models import Page ...@@ -20,8 +20,6 @@ from core.models import Page
from club.models import Club from club.models import Club
from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin from core.views import CanViewMixin, CanEditMixin, CanEditPropMixin, CanCreateMixin
from launderette.models import Launderette, Token, Machine, Slot from launderette.models import Launderette, Token, Machine, Slot
from subscription.views import get_subscriber
from subscription.models import Subscriber
from counter.models import Counter, Customer, Selling from counter.models import Counter, Customer, Selling
from counter.views import GetUserForm from counter.views import GetUserForm
...@@ -61,7 +59,7 @@ class LaunderetteBookView(CanViewMixin, DetailView): ...@@ -61,7 +59,7 @@ class LaunderetteBookView(CanViewMixin, DetailView):
if 'slot_type' in request.POST.keys(): if 'slot_type' in request.POST.keys():
self.slot_type = request.POST['slot_type'] self.slot_type = request.POST['slot_type']
if 'slot' in request.POST.keys() and request.user.is_authenticated(): if 'slot' in request.POST.keys() and request.user.is_authenticated():
self.subscriber = get_subscriber(request.user) self.subscriber = request.user
if self.subscriber.is_subscribed(): if self.subscriber.is_subscribed():
self.date = dateparse.parse_datetime(request.POST['slot']).replace(tzinfo=pytz.UTC) self.date = dateparse.parse_datetime(request.POST['slot']).replace(tzinfo=pytz.UTC)
if self.slot_type == "WASHING": if self.slot_type == "WASHING":
...@@ -224,7 +222,7 @@ class LaunderetteAdminView(CanEditPropMixin, BaseFormView, DetailView): ...@@ -224,7 +222,7 @@ class LaunderetteAdminView(CanEditPropMixin, BaseFormView, DetailView):
class GetLaunderetteUserForm(GetUserForm): class GetLaunderetteUserForm(GetUserForm):
def clean(self): def clean(self):
cleaned_data = super(GetLaunderetteUserForm, self).clean() cleaned_data = super(GetLaunderetteUserForm, self).clean()
sub = get_subscriber(cleaned_data['user']) sub = cleaned_data['user']
if sub.slots.all().count() <= 0: if sub.slots.all().count() <= 0:
raise forms.ValidationError(_("User has booked no slot")) raise forms.ValidationError(_("User has booked no slot"))
return cleaned_data return cleaned_data
...@@ -272,10 +270,10 @@ class LaunderetteMainClickView(CanEditMixin, BaseFormView, DetailView): ...@@ -272,10 +270,10 @@ class LaunderetteMainClickView(CanEditMixin, BaseFormView, DetailView):
class ClickTokenForm(forms.BaseForm): class ClickTokenForm(forms.BaseForm):
def clean(self): def clean(self):
with transaction.atomic(): with transaction.atomic():
operator = Subscriber.objects.filter(id=self.operator_id).first() operator = User.objects.filter(id=self.operator_id).first()
customer = Customer.objects.filter(user__id=self.subscriber_id).first() customer = Customer.objects.filter(user__id=self.subscriber_id).first()
counter = Counter.objects.filter(id=self.counter_id).first() counter = Counter.objects.filter(id=self.counter_id).first()
subscriber = get_subscriber(customer.user) subscriber = customer.user
self.last_basket = { self.last_basket = {
'last_basket': [], 'last_basket': [],
'last_customer': customer.user.get_display_name(), 'last_customer': customer.user.get_display_name(),
...@@ -334,7 +332,7 @@ class LaunderetteClickView(CanEditMixin, DetailView, BaseFormView): ...@@ -334,7 +332,7 @@ class LaunderetteClickView(CanEditMixin, DetailView, BaseFormView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
"""Simple get view""" """Simple get view"""
self.customer = Customer.objects.filter(user__id=self.kwargs['user_id']).first() self.customer = Customer.objects.filter(user__id=self.kwargs['user_id']).first()
self.subscriber = get_subscriber(self.customer.user) self.subscriber = self.customer.user
self.operator = request.user self.operator = request.user
return super(LaunderetteClickView, self).get(request, *args, **kwargs) return super(LaunderetteClickView, self).get(request, *args, **kwargs)
...@@ -342,7 +340,7 @@ class LaunderetteClickView(CanEditMixin, DetailView, BaseFormView): ...@@ -342,7 +340,7 @@ class LaunderetteClickView(CanEditMixin, DetailView, BaseFormView):
""" Handle the many possibilities of the post request """ """ Handle the many possibilities of the post request """
self.object = self.get_object() self.object = self.get_object()
self.customer = Customer.objects.filter(user__id=self.kwargs['user_id']).first() self.customer = Customer.objects.filter(user__id=self.kwargs['user_id']).first()
self.subscriber = get_subscriber(self.customer.user) self.subscriber = self.customer.user
self.operator = request.user self.operator = request.user
return super(LaunderetteClickView, self).post(request, *args, **kwargs) return super(LaunderetteClickView, self).post(request, *args, **kwargs)
......
...@@ -22,7 +22,7 @@ from django.core.files import File ...@@ -22,7 +22,7 @@ from django.core.files import File
from core.models import User, SithFile from core.models import User, SithFile
from club.models import Club, Membership from club.models import Club, Membership
from counter.models import Customer, Counter, Selling, Refilling, Product, ProductType, Permanency, Eticket from counter.models import Customer, Counter, Selling, Refilling, Product, ProductType, Permanency, Eticket
from subscription.models import Subscription, Subscriber from subscription.models import Subscription
from eboutic.models import Invoice, InvoiceItem from eboutic.models import Invoice, InvoiceItem
from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType, Company, SimplifiedAccountingType, Label from accounting.models import BankAccount, ClubAccount, GeneralJournal, Operation, AccountingType, Company, SimplifiedAccountingType, Label
from sas.models import Album, Picture, PeoplePictureRelation from sas.models import Album, Picture, PeoplePictureRelation
...@@ -298,7 +298,7 @@ def migrate_subscriptions(): ...@@ -298,7 +298,7 @@ def migrate_subscriptions():
print("Customers deleted") print("Customers deleted")
for r in cur: for r in cur:
try: try:
user = Subscriber.objects.filter(id=r['id_utilisateur']).first() user = User.objects.filter(id=r['id_utilisateur']).first()
if user: if user:
new = Subscription( new = Subscription(
id=r['id_cotisation'], id=r['id_cotisation'],
......
...@@ -8,7 +8,6 @@ from django.core.exceptions import PermissionDenied ...@@ -8,7 +8,6 @@ from django.core.exceptions import PermissionDenied
from ajax_select.fields import AutoCompleteSelectField from ajax_select.fields import AutoCompleteSelectField
from core.models import User from core.models import User
from subscription.models import Subscriber
from counter.models import Customer from counter.models import Customer
def merge_users(u1, u2): def merge_users(u1, u2):
...@@ -40,8 +39,8 @@ def merge_users(u1, u2): ...@@ -40,8 +39,8 @@ def merge_users(u1, u2):
f.auto_now = False f.auto_now = False
u1.invoices.add(i) u1.invoices.add(i)
u1.save() u1.save()
s1 = Subscriber.objects.filter(id=u1.id).first() s1 = User.objects.filter(id=u1.id).first()
s2 = Subscriber.objects.filter(id=u2.id).first() s2 = User.objects.filter(id=u2.id).first()
for s in s2.subscriptions.all(): for s in s2.subscriptions.all():
s1.subscriptions.add(s) s1.subscriptions.add(s)
s1.save() s1.save()
......