mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-26 14:42:25 +00:00
Ajoute une app pour les factures
This commit is contained in:
parent
723ca43fe7
commit
ccb42d0abc
19 changed files with 236 additions and 0 deletions
0
cotisations/__init__.py
Normal file
0
cotisations/__init__.py
Normal file
BIN
cotisations/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
cotisations/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
BIN
cotisations/__pycache__/admin.cpython-34.pyc
Normal file
BIN
cotisations/__pycache__/admin.cpython-34.pyc
Normal file
Binary file not shown.
BIN
cotisations/__pycache__/models.cpython-34.pyc
Normal file
BIN
cotisations/__pycache__/models.cpython-34.pyc
Normal file
Binary file not shown.
BIN
cotisations/__pycache__/urls.cpython-34.pyc
Normal file
BIN
cotisations/__pycache__/urls.cpython-34.pyc
Normal file
Binary file not shown.
BIN
cotisations/__pycache__/views.cpython-34.pyc
Normal file
BIN
cotisations/__pycache__/views.cpython-34.pyc
Normal file
Binary file not shown.
3
cotisations/admin.py
Normal file
3
cotisations/admin.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
60
cotisations/migrations/0001_initial.py
Normal file
60
cotisations/migrations/0001_initial.py
Normal file
|
@ -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),
|
||||
),
|
||||
]
|
0
cotisations/migrations/__init__.py
Normal file
0
cotisations/migrations/__init__.py
Normal file
BIN
cotisations/migrations/__pycache__/0001_initial.cpython-34.pyc
Normal file
BIN
cotisations/migrations/__pycache__/0001_initial.cpython-34.pyc
Normal file
Binary file not shown.
BIN
cotisations/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
BIN
cotisations/migrations/__pycache__/__init__.cpython-34.pyc
Normal file
Binary file not shown.
68
cotisations/models.py
Normal file
68
cotisations/models.py
Normal file
|
@ -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']
|
14
cotisations/templates/cotisations/facture.html
Normal file
14
cotisations/templates/cotisations/facture.html
Normal file
|
@ -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 %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form factureform %}
|
||||
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
|
||||
</form>
|
||||
{% endblock %}
|
28
cotisations/templates/cotisations/index.html
Normal file
28
cotisations/templates/cotisations/index.html
Normal file
|
@ -0,0 +1,28 @@
|
|||
{% extends "cotisations/sidebar.html" %}
|
||||
{% load bootstrap3 %}
|
||||
|
||||
{% block title %}Facture{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Designation</th>
|
||||
<th>Utilisateur</th>
|
||||
<th>Article</th>
|
||||
<th>Moyen de paiement</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for user in users_list %}
|
||||
<tr>
|
||||
<td>{{ facture_list.name }}</td>
|
||||
<td>{{ facture_list.user }}</td>
|
||||
<td>{{ facture_list.article }}</td>
|
||||
<td>{{ facture_list.paiement }}</td>
|
||||
<td>{{ facture_list.date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
7
cotisations/templates/cotisations/sidebar.html
Normal file
7
cotisations/templates/cotisations/sidebar.html
Normal file
|
@ -0,0 +1,7 @@
|
|||
{% extends "base.html" %}
|
||||
|
||||
{% block sidebar %}
|
||||
<p><a href="{% url "search:search" %}">Créer une facture</a></p>
|
||||
<p><a href="{% url "search:search" %}">Editer une facture</a></p>
|
||||
<p><a href="{% url "cotisations:index" %}">Liste des factures</a></p>
|
||||
{% endblock %}
|
3
cotisations/tests.py
Normal file
3
cotisations/tests.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.test import TestCase
|
||||
|
||||
# Create your tests here.
|
11
cotisations/urls.py
Normal file
11
cotisations/urls.py
Normal file
|
@ -0,0 +1,11 @@
|
|||
from django.conf.urls import url
|
||||
|
||||
from . import views
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^new_facture/(?P<userid>[0-9]+)$', views.new_facture, name='new-facture'),
|
||||
url(r'^edit_facture/(?P<factureid>[0-9]+)$', views.edit_facture, name='edit-facture'),
|
||||
url(r'^$', views.index, name='index'),
|
||||
]
|
||||
|
||||
|
41
cotisations/views.py
Normal file
41
cotisations/views.py
Normal file
|
@ -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})
|
|
@ -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')),
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue