diff --git a/cotisations/__init__.py b/cotisations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cotisations/__pycache__/__init__.cpython-34.pyc b/cotisations/__pycache__/__init__.cpython-34.pyc new file mode 100644 index 00000000..ca281b35 Binary files /dev/null and b/cotisations/__pycache__/__init__.cpython-34.pyc differ diff --git a/cotisations/__pycache__/admin.cpython-34.pyc b/cotisations/__pycache__/admin.cpython-34.pyc new file mode 100644 index 00000000..0e4e2221 Binary files /dev/null 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 new file mode 100644 index 00000000..30b89c47 Binary files /dev/null and b/cotisations/__pycache__/models.cpython-34.pyc differ diff --git a/cotisations/__pycache__/urls.cpython-34.pyc b/cotisations/__pycache__/urls.cpython-34.pyc new file mode 100644 index 00000000..5e1e4a2d Binary files /dev/null and b/cotisations/__pycache__/urls.cpython-34.pyc differ diff --git a/cotisations/__pycache__/views.cpython-34.pyc b/cotisations/__pycache__/views.cpython-34.pyc new file mode 100644 index 00000000..fa02e8e8 Binary files /dev/null and b/cotisations/__pycache__/views.cpython-34.pyc differ diff --git a/cotisations/admin.py b/cotisations/admin.py new file mode 100644 index 00000000..8c38f3f3 --- /dev/null +++ b/cotisations/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/cotisations/migrations/0001_initial.py b/cotisations/migrations/0001_initial.py new file mode 100644 index 00000000..17471716 --- /dev/null +++ b/cotisations/migrations/0001_initial.py @@ -0,0 +1,60 @@ +# -*- 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', '0005_auto_20160702_0006'), + ] + + operations = [ + migrations.CreateModel( + name='Article', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=255)), + ('prix', models.DecimalField(decimal_places=2, max_digits=5)), + ], + ), + migrations.CreateModel( + name='Banque', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)), + ('name', models.CharField(max_length=255)), + ], + ), + migrations.CreateModel( + name='Facture', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)), + ('cheque', models.CharField(max_length=255)), + ('number', models.IntegerField()), + ('date', models.DateTimeField(auto_now_add=True)), + ('name', models.CharField(max_length=255)), + ('prix', models.DecimalField(decimal_places=2, max_digits=5)), + ('article', models.ForeignKey(to='cotisations.Article', on_delete=django.db.models.deletion.PROTECT)), + ('banque', models.ForeignKey(to='cotisations.Banque', on_delete=django.db.models.deletion.PROTECT)), + ], + ), + migrations.CreateModel( + name='Paiement', + fields=[ + ('id', models.AutoField(verbose_name='ID', auto_created=True, primary_key=True, serialize=False)), + ('moyen', models.CharField(max_length=255)), + ], + ), + migrations.AddField( + model_name='facture', + name='paiement', + field=models.ForeignKey(to='cotisations.Paiement', on_delete=django.db.models.deletion.PROTECT), + ), + migrations.AddField( + model_name='facture', + name='user', + field=models.ForeignKey(to='users.User', on_delete=django.db.models.deletion.PROTECT), + ), + ] diff --git a/cotisations/migrations/__init__.py b/cotisations/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/cotisations/migrations/__pycache__/0001_initial.cpython-34.pyc b/cotisations/migrations/__pycache__/0001_initial.cpython-34.pyc new file mode 100644 index 00000000..5f39a713 Binary files /dev/null and b/cotisations/migrations/__pycache__/0001_initial.cpython-34.pyc differ diff --git a/cotisations/migrations/__pycache__/__init__.cpython-34.pyc b/cotisations/migrations/__pycache__/__init__.cpython-34.pyc new file mode 100644 index 00000000..ab177145 Binary files /dev/null and b/cotisations/migrations/__pycache__/__init__.cpython-34.pyc differ diff --git a/cotisations/models.py b/cotisations/models.py new file mode 100644 index 00000000..170cdd3a --- /dev/null +++ b/cotisations/models.py @@ -0,0 +1,68 @@ +from django.db import models +from django import forms +from django.forms import ModelForm + +from users.models import User + +class Facture(models.Model): + user = models.ForeignKey('users.User', on_delete=models.PROTECT) + article = models.ForeignKey('Article', on_delete=models.PROTECT) + paiement = models.ForeignKey('Paiement', on_delete=models.PROTECT) + banque = models.ForeignKey('Banque', on_delete=models.PROTECT) + cheque = models.CharField(max_length=255) + number = models.IntegerField() + date = models.DateTimeField(auto_now_add=True) + name = models.CharField(max_length=255) + prix = models.DecimalField(max_digits=5, decimal_places=2) + + def __str__(self): + return str(self.name) + ' ' + str(self.article) + +class Article(models.Model): + name = models.CharField(max_length=255) + prix = models.DecimalField(max_digits=5, decimal_places=2) + + def __str__(self): + return self.name + +class Banque(models.Model): + name = models.CharField(max_length=255) + + def __str__(self): + return self.name + +class Paiement(models.Model): + moyen = models.CharField(max_length=255) + + def __str__(self): + return self.moyen + +class NewFactureForm(ModelForm): + article = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Article") + + def __init__(self, *args, **kwargs): + super(NewFactureForm, self).__init__(*args, **kwargs) + self.fields['user'].label = 'Adherent' + self.fields['number'].label = 'Quantité' + self.fields['cheque'].required = False + self.fields['banque'].required = False + self.fields['cheque'].label = 'Numero de chèque' + + class Meta: + model = Facture + exclude = ['name', 'prix'] + +class EditFactureForm(ModelForm): + def __init__(self, *args, **kwargs): + super(EditFactureForm, self).__init__(*args, **kwargs) + self.fields['user'].label = 'Adherent' + self.fields['number'].label = 'Quantité' + self.fields['cheque'].required = False + self.fields['banque'].required = False + self.fields['cheque'].label = 'Numero de chèque' + self.fields['name'].label = 'Designation' + self.fields['prix'].label = 'Prix unitaire' + + class Meta: + model = Facture + exclude = ['user'] diff --git a/cotisations/templates/cotisations/facture.html b/cotisations/templates/cotisations/facture.html new file mode 100644 index 00000000..8b2b9b58 --- /dev/null +++ b/cotisations/templates/cotisations/facture.html @@ -0,0 +1,14 @@ +{% extends "users/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Création et modification de factures{% endblock %} + +{% block content %} +{% bootstrap_form_errors userform %} + +
+ {% csrf_token %} + {% bootstrap_form factureform %} + {% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %} +
+{% endblock %} diff --git a/cotisations/templates/cotisations/index.html b/cotisations/templates/cotisations/index.html new file mode 100644 index 00000000..a65b18ed --- /dev/null +++ b/cotisations/templates/cotisations/index.html @@ -0,0 +1,28 @@ +{% extends "cotisations/sidebar.html" %} +{% load bootstrap3 %} + +{% block title %}Facture{% endblock %} + +{% block content %} + + + + + + + + + + + {% for user in users_list %} + + + + + + + + {% endfor %} +
DesignationUtilisateurArticleMoyen de paiementDate
{{ facture_list.name }}{{ facture_list.user }}{{ facture_list.article }}{{ facture_list.paiement }}{{ facture_list.date }}
+{% endblock %} + diff --git a/cotisations/templates/cotisations/sidebar.html b/cotisations/templates/cotisations/sidebar.html new file mode 100644 index 00000000..8894fcbb --- /dev/null +++ b/cotisations/templates/cotisations/sidebar.html @@ -0,0 +1,7 @@ +{% extends "base.html" %} + +{% block sidebar %} +

Créer une facture

+

Editer une facture

+

Liste des factures

+{% endblock %} diff --git a/cotisations/tests.py b/cotisations/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/cotisations/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/cotisations/urls.py b/cotisations/urls.py new file mode 100644 index 00000000..3c0bbdf7 --- /dev/null +++ b/cotisations/urls.py @@ -0,0 +1,11 @@ +from django.conf.urls import url + +from . import views + +urlpatterns = [ + url(r'^new_facture/(?P[0-9]+)$', views.new_facture, name='new-facture'), + url(r'^edit_facture/(?P[0-9]+)$', views.edit_facture, name='edit-facture'), + url(r'^$', views.index, name='index'), +] + + diff --git a/cotisations/views.py b/cotisations/views.py new file mode 100644 index 00000000..a5fa5549 --- /dev/null +++ b/cotisations/views.py @@ -0,0 +1,41 @@ +# App de gestion des users pour re2o +# Goulven Kermarec, Gabriel Détraz +# Gplv2 +from django.shortcuts import render, redirect +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 cotisations.models import NewFactureForm, EditFactureForm, Facture, Article + +def form(ctx, template, request): + c = ctx + c.update(csrf(request)) + return render_to_response(template, c, context_instance=RequestContext(request)) + +def new_facture(request, userid): + facture = Facture.objects.create(user=userid) + facture_form = NewFactureForm(request.POST or None, instance=facture) + if facture_form.is_valid(): + facture_form.save() + messages.success(request, "La facture a été crée") + return redirect("/cotisations/") + return form({'factureform': facture_form}, 'cotisations/facture.html', request) + +def edit_facture(request, factureid): + try: + facture = Facture.objects.get(pk=factureid) + except Facture.DoesNotExist: + messages.error(request, u"Facture inexistante" ) + return redirect("/cotisations/") + facture_form = EditFactureForm(request.POST or None, instance=facture) + if facture_form.is_valid(): + facture_form.save() + messages.success(request, "La facture a bien été modifiée") + return redirect("/cotisations/") + return form({'factureform': facture}, 'cotisations/facture.html', request) + +def index(request): + facture_list = Facture.objects.order_by('pk') + return render(request, 'cotisations/index.html', {'facture_list': facture_list}) diff --git a/re2o/urls.py b/re2o/urls.py index 6bcabc24..89fd34cd 100644 --- a/re2o/urls.py +++ b/re2o/urls.py @@ -22,5 +22,6 @@ urlpatterns = [ url(r'^admin/', include(admin.site.urls)), url(r'^users/', include('users.urls', namespace='users')), url(r'^search/', include('search.urls', namespace='search')), + url(r'^cotisations/', include('cotisations.urls', namespace='cotisations')), #url(r'^logs/', include('logs.urls', namespace='logs')), ]