mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-23 03:43:12 +00:00
Gestion complète des cotisations, lorsque la facture concerne une cotisation
This commit is contained in:
parent
233d68c64b
commit
892dc7ee3e
27 changed files with 140 additions and 6 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
19
cotisations/migrations/0010_auto_20160702_1840.py
Normal file
19
cotisations/migrations/0010_auto_20160702_1840.py
Normal file
|
@ -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),
|
||||||
|
),
|
||||||
|
]
|
19
cotisations/migrations/0011_auto_20160702_1911.py
Normal file
19
cotisations/migrations/0011_auto_20160702_1911.py
Normal file
|
@ -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(),
|
||||||
|
),
|
||||||
|
]
|
Binary file not shown.
Binary file not shown.
|
@ -22,7 +22,7 @@ class Article(models.Model):
|
||||||
name = models.CharField(max_length=255)
|
name = models.CharField(max_length=255)
|
||||||
prix = models.DecimalField(max_digits=5, decimal_places=2)
|
prix = models.DecimalField(max_digits=5, decimal_places=2)
|
||||||
cotisation = models.BooleanField()
|
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):
|
def __str__(self):
|
||||||
return self.name
|
return self.name
|
||||||
|
@ -41,7 +41,7 @@ class Paiement(models.Model):
|
||||||
|
|
||||||
class Cotisation(models.Model):
|
class Cotisation(models.Model):
|
||||||
facture = models.ForeignKey('Facture', on_delete=models.PROTECT)
|
facture = models.ForeignKey('Facture', on_delete=models.PROTECT)
|
||||||
date_start = models.DateTimeField(auto_now_add=True)
|
date_start = models.DateTimeField()
|
||||||
date_end = models.DateTimeField()
|
date_end = models.DateTimeField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -59,7 +59,7 @@ class NewFactureForm(ModelForm):
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Facture
|
model = Facture
|
||||||
exclude = ['user', 'prix', 'name']
|
exclude = ['user', 'prix', 'name', 'valid']
|
||||||
|
|
||||||
class EditFactureForm(ModelForm):
|
class EditFactureForm(ModelForm):
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
{% extends "users/sidebar.html" %}
|
{% extends "cotisations/sidebar.html" %}
|
||||||
{% load bootstrap3 %}
|
{% load bootstrap3 %}
|
||||||
|
|
||||||
{% block title %}Création et modification de factures{% endblock %}
|
{% block title %}Création et modification de factures{% endblock %}
|
||||||
|
|
|
@ -6,15 +6,34 @@ from django.shortcuts import render_to_response, get_object_or_404
|
||||||
from django.core.context_processors import csrf
|
from django.core.context_processors import csrf
|
||||||
from django.template import Context, RequestContext, loader
|
from django.template import Context, RequestContext, loader
|
||||||
from django.contrib import messages
|
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 users.models import User
|
||||||
|
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
import datetime
|
||||||
|
|
||||||
def form(ctx, template, request):
|
def form(ctx, template, request):
|
||||||
c = ctx
|
c = ctx
|
||||||
c.update(csrf(request))
|
c.update(csrf(request))
|
||||||
return render_to_response(template, c, context_instance=RequestContext(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):
|
def new_facture(request, userid):
|
||||||
try:
|
try:
|
||||||
user = User.objects.get(pk=userid)
|
user = User.objects.get(pk=userid)
|
||||||
|
@ -29,7 +48,11 @@ def new_facture(request, userid):
|
||||||
new_facture.prix = article[0].prix
|
new_facture.prix = article[0].prix
|
||||||
new_facture.name = article[0].name
|
new_facture.name = article[0].name
|
||||||
new_facture.save()
|
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 redirect("/cotisations/")
|
||||||
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
|
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
|
||||||
|
|
||||||
|
|
BIN
users/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
users/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/admin.cpython-34.pyc
Normal file
BIN
users/__pycache__/admin.cpython-34.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/forms.cpython-34.pyc
Normal file
BIN
users/__pycache__/forms.cpython-34.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/models.cpython-34.pyc
Normal file
BIN
users/__pycache__/models.cpython-34.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/urls.cpython-34.pyc
Normal file
BIN
users/__pycache__/urls.cpython-34.pyc
Normal file
Binary file not shown.
BIN
users/__pycache__/views.cpython-34.pyc
Normal file
BIN
users/__pycache__/views.cpython-34.pyc
Normal file
Binary file not shown.
30
users/migrations/0003_listrights_rights.py
Normal file
30
users/migrations/0003_listrights_rights.py
Normal file
|
@ -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')),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
]
|
22
users/migrations/0004_auto_20160701_2312.py
Normal file
22
users/migrations/0004_auto_20160701_2312.py
Normal file
|
@ -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',
|
||||||
|
),
|
||||||
|
]
|
18
users/migrations/0005_auto_20160702_0006.py
Normal file
18
users/migrations/0005_auto_20160702_0006.py
Normal file
|
@ -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')]),
|
||||||
|
),
|
||||||
|
]
|
BIN
users/migrations/__pycache__/0001_initial.cpython-34.pyc
Normal file
BIN
users/migrations/__pycache__/0001_initial.cpython-34.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
users/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
users/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
|
@ -101,3 +101,4 @@ class DelRightForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Right
|
model = Right
|
||||||
exclude = ['user', 'right']
|
exclude = ['user', 'right']
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
<th>Prénom</th>
|
<th>Prénom</th>
|
||||||
<th>Nom</th>
|
<th>Nom</th>
|
||||||
<th>Pseudo</th>
|
<th>Pseudo</th>
|
||||||
|
<th>Modifier</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
{% for user in users_list %}
|
{% for user in users_list %}
|
||||||
|
@ -17,6 +18,7 @@
|
||||||
<td>{{ user.name }}</td>
|
<td>{{ user.name }}</td>
|
||||||
<td>{{ user.surname }}</td>
|
<td>{{ user.surname }}</td>
|
||||||
<td>{{ user.pseudo }}</td>
|
<td>{{ user.pseudo }}</td>
|
||||||
|
<td><a href="{% url 'users:edit-info' user.id %}">Editer</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in a new issue