8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 22:52:26 +00:00

Gestion complète des cotisations, lorsque la facture concerne une cotisation

This commit is contained in:
Gabriel Detraz 2016-07-02 21:17:21 +02:00
parent 233d68c64b
commit 892dc7ee3e
27 changed files with 140 additions and 6 deletions

View 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),
),
]

View 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(),
),
]

View file

@ -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):

View file

@ -1,4 +1,4 @@
{% extends "users/sidebar.html" %}
{% extends "cotisations/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Création et modification de factures{% endblock %}

View file

@ -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,6 +48,10 @@ def new_facture(request, userid):
new_facture.prix = article[0].prix
new_facture.name = article[0].name
new_facture.save()
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)

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View 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')),
],
),
]

View 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',
),
]

View 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')]),
),
]

Binary file not shown.

View file

@ -101,3 +101,4 @@ class DelRightForm(ModelForm):
class Meta:
model = Right
exclude = ['user', 'right']

View file

@ -10,6 +10,7 @@
<th>Prénom</th>
<th>Nom</th>
<th>Pseudo</th>
<th>Modifier</th>
</tr>
</thead>
{% for user in users_list %}
@ -17,6 +18,7 @@
<td>{{ user.name }}</td>
<td>{{ user.surname }}</td>
<td>{{ user.pseudo }}</td>
<td><a href="{% url 'users:edit-info' user.id %}">Editer</a></td>
</tr>
{% endfor %}
</table>