diff --git a/cotisations/__pycache__/admin.cpython-34.pyc b/cotisations/__pycache__/admin.cpython-34.pyc index a11e9707..49d9c42e 100644 Binary files a/cotisations/__pycache__/admin.cpython-34.pyc and b/cotisations/__pycache__/admin.cpython-34.pyc differ diff --git a/cotisations/__pycache__/models.cpython-34.pyc b/cotisations/__pycache__/models.cpython-34.pyc index faed6fa7..69fc1814 100644 Binary files a/cotisations/__pycache__/models.cpython-34.pyc and b/cotisations/__pycache__/models.cpython-34.pyc differ diff --git a/cotisations/__pycache__/views.cpython-34.pyc b/cotisations/__pycache__/views.cpython-34.pyc index 2a66acfd..c1fe5b15 100644 Binary files a/cotisations/__pycache__/views.cpython-34.pyc and b/cotisations/__pycache__/views.cpython-34.pyc differ diff --git a/cotisations/migrations/0010_auto_20160702_1840.py b/cotisations/migrations/0010_auto_20160702_1840.py new file mode 100644 index 00000000..fddacb5f --- /dev/null +++ b/cotisations/migrations/0010_auto_20160702_1840.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0009_remove_cotisation_user'), + ] + + operations = [ + migrations.AlterField( + model_name='article', + name='duration', + field=models.IntegerField(null=True, help_text='Durée exprimée en mois entiers', blank=True), + ), + ] diff --git a/cotisations/migrations/0011_auto_20160702_1911.py b/cotisations/migrations/0011_auto_20160702_1911.py new file mode 100644 index 00000000..aafb9ee9 --- /dev/null +++ b/cotisations/migrations/0011_auto_20160702_1911.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0010_auto_20160702_1840'), + ] + + operations = [ + migrations.AlterField( + model_name='cotisation', + name='date_start', + field=models.DateTimeField(), + ), + ] diff --git a/cotisations/migrations/__pycache__/0010_auto_20160702_1840.cpython-34.pyc b/cotisations/migrations/__pycache__/0010_auto_20160702_1840.cpython-34.pyc new file mode 100644 index 00000000..04664eff Binary files /dev/null and b/cotisations/migrations/__pycache__/0010_auto_20160702_1840.cpython-34.pyc differ diff --git a/cotisations/migrations/__pycache__/0011_auto_20160702_1911.cpython-34.pyc b/cotisations/migrations/__pycache__/0011_auto_20160702_1911.cpython-34.pyc new file mode 100644 index 00000000..2a332f67 Binary files /dev/null and b/cotisations/migrations/__pycache__/0011_auto_20160702_1911.cpython-34.pyc differ diff --git a/cotisations/models.py b/cotisations/models.py index 195a70c8..e1a1a780 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -22,7 +22,7 @@ class Article(models.Model): name = models.CharField(max_length=255) prix = models.DecimalField(max_digits=5, decimal_places=2) cotisation = models.BooleanField() - duration = models.DurationField(blank=True, null=True) + duration = models.IntegerField(help_text="Durée exprimée en mois entiers", blank=True, null=True) def __str__(self): return self.name @@ -41,7 +41,7 @@ class Paiement(models.Model): class Cotisation(models.Model): facture = models.ForeignKey('Facture', on_delete=models.PROTECT) - date_start = models.DateTimeField(auto_now_add=True) + date_start = models.DateTimeField() date_end = models.DateTimeField() def __str__(self): @@ -59,7 +59,7 @@ class NewFactureForm(ModelForm): class Meta: model = Facture - exclude = ['user', 'prix', 'name'] + exclude = ['user', 'prix', 'name', 'valid'] class EditFactureForm(ModelForm): def __init__(self, *args, **kwargs): diff --git a/cotisations/templates/cotisations/facture.html b/cotisations/templates/cotisations/facture.html index dd3b917b..48147b96 100644 --- a/cotisations/templates/cotisations/facture.html +++ b/cotisations/templates/cotisations/facture.html @@ -1,4 +1,4 @@ -{% extends "users/sidebar.html" %} +{% extends "cotisations/sidebar.html" %} {% load bootstrap3 %} {% block title %}Création et modification de factures{% endblock %} diff --git a/cotisations/views.py b/cotisations/views.py index 535f91cd..4a0f15c6 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -6,15 +6,34 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.core.context_processors import csrf from django.template import Context, RequestContext, loader from django.contrib import messages +from django.db.models import Max -from cotisations.models import NewFactureForm, EditFactureForm, Facture, Article +from cotisations.models import NewFactureForm, EditFactureForm, Facture, Article, Cotisation from users.models import User +from dateutil.relativedelta import relativedelta +import datetime + def form(ctx, template, request): c = ctx c.update(csrf(request)) return render_to_response(template, c, context_instance=RequestContext(request)) +def end_adhesion(user): + """ Renvoie la date de fin d'adhésion d'un user, False sinon """ + date_max = Cotisation.objects.all().filter(facture=Facture.objects.all().filter(user=user)).aggregate(Max('date_end'))['date_end__max'] + return date_max + +def create_cotis(facture, user, article): + """ Update et crée l'objet cotisation associé à une facture, prend en argument l'user, la facture pour la quantitéi, et l'article pour la durée""" + cotisation=Cotisation(facture=facture) + date_max = end_adhesion(user) or datetime.datetime.now() + if date_max: + cotisation.date_start=date_max + cotisation.date_end = cotisation.date_start + relativedelta(months=article[0].duration*facture.number) + cotisation.save() + return + def new_facture(request, userid): try: user = User.objects.get(pk=userid) @@ -29,7 +48,11 @@ def new_facture(request, userid): new_facture.prix = article[0].prix new_facture.name = article[0].name new_facture.save() - messages.success(request, "La facture a été crée") + if article[0].cotisation == True: + create_cotis(new_facture, user, article) + messages.success(request, "La cotisation a été prolongée pour l'adhérent %s " % user.name ) + else: + messages.success(request, "La facture a été crée") return redirect("/cotisations/") return form({'factureform': facture_form}, 'cotisations/facture.html', request) diff --git a/users/__pycache__/__init__.cpython-34.pyc b/users/__pycache__/__init__.cpython-34.pyc new file mode 100644 index 00000000..864eb52b Binary files /dev/null and b/users/__pycache__/__init__.cpython-34.pyc differ diff --git a/users/__pycache__/admin.cpython-34.pyc b/users/__pycache__/admin.cpython-34.pyc new file mode 100644 index 00000000..4cf1c0fd Binary files /dev/null and b/users/__pycache__/admin.cpython-34.pyc differ diff --git a/users/__pycache__/forms.cpython-34.pyc b/users/__pycache__/forms.cpython-34.pyc new file mode 100644 index 00000000..addd80c1 Binary files /dev/null and b/users/__pycache__/forms.cpython-34.pyc differ diff --git a/users/__pycache__/models.cpython-34.pyc b/users/__pycache__/models.cpython-34.pyc new file mode 100644 index 00000000..bad97be0 Binary files /dev/null and b/users/__pycache__/models.cpython-34.pyc differ diff --git a/users/__pycache__/urls.cpython-34.pyc b/users/__pycache__/urls.cpython-34.pyc new file mode 100644 index 00000000..15c7aa6a Binary files /dev/null and b/users/__pycache__/urls.cpython-34.pyc differ diff --git a/users/__pycache__/views.cpython-34.pyc b/users/__pycache__/views.cpython-34.pyc new file mode 100644 index 00000000..d4ffd82d Binary files /dev/null and b/users/__pycache__/views.cpython-34.pyc differ diff --git a/users/migrations/0003_listrights_rights.py b/users/migrations/0003_listrights_rights.py new file mode 100644 index 00000000..01257a4f --- /dev/null +++ b/users/migrations/0003_listrights_rights.py @@ -0,0 +1,30 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0002_auto_20160630_2301'), + ] + + operations = [ + migrations.CreateModel( + name='ListRights', + fields=[ + ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('listright', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Rights', + fields=[ + ('id', models.AutoField(serialize=False, primary_key=True, auto_created=True, verbose_name='ID')), + ('right', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='users.ListRights')), + ('user', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='users.User')), + ], + ), + ] diff --git a/users/migrations/0004_auto_20160701_2312.py b/users/migrations/0004_auto_20160701_2312.py new file mode 100644 index 00000000..e42b036b --- /dev/null +++ b/users/migrations/0004_auto_20160701_2312.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0003_listrights_rights'), + ] + + operations = [ + migrations.RenameModel( + old_name='ListRights', + new_name='ListRight', + ), + migrations.RenameModel( + old_name='Rights', + new_name='Right', + ), + ] diff --git a/users/migrations/0005_auto_20160702_0006.py b/users/migrations/0005_auto_20160702_0006.py new file mode 100644 index 00000000..1cb0721c --- /dev/null +++ b/users/migrations/0005_auto_20160702_0006.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('users', '0004_auto_20160701_2312'), + ] + + operations = [ + migrations.AlterUniqueTogether( + name='right', + unique_together=set([('user', 'right')]), + ), + ] diff --git a/users/migrations/__pycache__/0001_initial.cpython-34.pyc b/users/migrations/__pycache__/0001_initial.cpython-34.pyc new file mode 100644 index 00000000..2341cf42 Binary files /dev/null and b/users/migrations/__pycache__/0001_initial.cpython-34.pyc differ diff --git a/users/migrations/__pycache__/0002_auto_20160630_2301.cpython-34.pyc b/users/migrations/__pycache__/0002_auto_20160630_2301.cpython-34.pyc new file mode 100644 index 00000000..ef14af19 Binary files /dev/null and b/users/migrations/__pycache__/0002_auto_20160630_2301.cpython-34.pyc differ diff --git a/users/migrations/__pycache__/0003_listrights_rights.cpython-34.pyc b/users/migrations/__pycache__/0003_listrights_rights.cpython-34.pyc new file mode 100644 index 00000000..94e2dc8a Binary files /dev/null and b/users/migrations/__pycache__/0003_listrights_rights.cpython-34.pyc differ diff --git a/users/migrations/__pycache__/0004_auto_20160701_2312.cpython-34.pyc b/users/migrations/__pycache__/0004_auto_20160701_2312.cpython-34.pyc new file mode 100644 index 00000000..cb3aea6c Binary files /dev/null and b/users/migrations/__pycache__/0004_auto_20160701_2312.cpython-34.pyc differ diff --git a/users/migrations/__pycache__/0005_auto_20160702_0006.cpython-34.pyc b/users/migrations/__pycache__/0005_auto_20160702_0006.cpython-34.pyc new file mode 100644 index 00000000..711dcac3 Binary files /dev/null and b/users/migrations/__pycache__/0005_auto_20160702_0006.cpython-34.pyc differ diff --git a/users/migrations/__pycache__/__init__.cpython-34.pyc b/users/migrations/__pycache__/__init__.cpython-34.pyc new file mode 100644 index 00000000..abba301a Binary files /dev/null and b/users/migrations/__pycache__/__init__.cpython-34.pyc differ diff --git a/users/models.py b/users/models.py index 4867a3df..333ac569 100644 --- a/users/models.py +++ b/users/models.py @@ -101,3 +101,4 @@ class DelRightForm(ModelForm): class Meta: model = Right exclude = ['user', 'right'] + diff --git a/users/templates/users/index.html b/users/templates/users/index.html index a11c47bc..a2f9ce5d 100644 --- a/users/templates/users/index.html +++ b/users/templates/users/index.html @@ -10,6 +10,7 @@