mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 16:33:47 +00:00
Fonction de création et d'edition de factures parfaitement fonctionnelle
This commit is contained in:
parent
e96881e69e
commit
e2055ab95c
20 changed files with 178 additions and 20 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,3 +1,20 @@
|
|||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
||||
from .models import Facture, Article, Banque, Paiement
|
||||
|
||||
class FactureAdmin(admin.ModelAdmin):
|
||||
list_display = ('user','paiement','name', 'number', 'date')
|
||||
|
||||
class ArticleAdmin(admin.ModelAdmin):
|
||||
list_display = ('name','prix')
|
||||
|
||||
class BanqueAdmin(admin.ModelAdmin):
|
||||
list_display = ('name',)
|
||||
|
||||
class PaiementAdmin(admin.ModelAdmin):
|
||||
list_display = ('moyen',)
|
||||
|
||||
admin.site.register(Facture, FactureAdmin)
|
||||
admin.site.register(Article, ArticleAdmin)
|
||||
admin.site.register(Banque, BanqueAdmin)
|
||||
admin.site.register(Paiement, PaiementAdmin)
|
||||
|
|
18
cotisations/migrations/0002_remove_facture_article.py
Normal file
18
cotisations/migrations/0002_remove_facture_article.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 = [
|
||||
('cotisations', '0001_initial'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.RemoveField(
|
||||
model_name='facture',
|
||||
name='article',
|
||||
),
|
||||
]
|
20
cotisations/migrations/0003_auto_20160702_1448.py
Normal file
20
cotisations/migrations/0003_auto_20160702_1448.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cotisations', '0002_remove_facture_article'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='banque',
|
||||
field=models.ForeignKey(blank=True, to='cotisations.Banque', on_delete=django.db.models.deletion.PROTECT, null=True),
|
||||
),
|
||||
]
|
24
cotisations/migrations/0004_auto_20160702_1528.py
Normal file
24
cotisations/migrations/0004_auto_20160702_1528.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cotisations', '0003_auto_20160702_1448'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='name',
|
||||
field=models.CharField(null=True, max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='prix',
|
||||
field=models.DecimalField(max_digits=5, null=True, decimal_places=2),
|
||||
),
|
||||
]
|
19
cotisations/migrations/0005_auto_20160702_1532.py
Normal file
19
cotisations/migrations/0005_auto_20160702_1532.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', '0004_auto_20160702_1528'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='cheque',
|
||||
field=models.CharField(max_length=255, blank=True),
|
||||
),
|
||||
]
|
24
cotisations/migrations/0006_auto_20160702_1534.py
Normal file
24
cotisations/migrations/0006_auto_20160702_1534.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cotisations', '0005_auto_20160702_1532'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='name',
|
||||
field=models.CharField(null=True, default='plop', max_length=255),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='prix',
|
||||
field=models.DecimalField(null=True, decimal_places=2, default=1, max_digits=5),
|
||||
),
|
||||
]
|
26
cotisations/migrations/0007_auto_20160702_1543.py
Normal file
26
cotisations/migrations/0007_auto_20160702_1543.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('cotisations', '0006_auto_20160702_1534'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='name',
|
||||
field=models.CharField(default='plop', max_length=255),
|
||||
preserve_default=False,
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='facture',
|
||||
name='prix',
|
||||
field=models.DecimalField(default=1, max_digits=5, decimal_places=2),
|
||||
preserve_default=False,
|
||||
),
|
||||
]
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -6,17 +6,16 @@ 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)
|
||||
banque = models.ForeignKey('Banque', on_delete=models.PROTECT, blank=True, null=True)
|
||||
cheque = models.CharField(max_length=255, blank=True)
|
||||
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)
|
||||
return str(self.name)
|
||||
|
||||
class Article(models.Model):
|
||||
name = models.CharField(max_length=255)
|
||||
|
@ -42,7 +41,6 @@ class NewFactureForm(ModelForm):
|
|||
|
||||
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
|
||||
|
@ -50,7 +48,7 @@ class NewFactureForm(ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = Facture
|
||||
exclude = ['name', 'prix']
|
||||
exclude = ['user', 'prix', 'name']
|
||||
|
||||
class EditFactureForm(ModelForm):
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
@ -65,4 +63,4 @@ class EditFactureForm(ModelForm):
|
|||
|
||||
class Meta:
|
||||
model = Facture
|
||||
exclude = ['user']
|
||||
fields = '__all__'
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
{% block title %}Création et modification de factures{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
{% bootstrap_form_errors userform %}
|
||||
{% bootstrap_form_errors factureform %}
|
||||
|
||||
<form class="form" method="post">
|
||||
{% csrf_token %}
|
||||
|
|
|
@ -7,20 +7,22 @@
|
|||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Designation</th>
|
||||
<th>Utilisateur</th>
|
||||
<th>Article</th>
|
||||
<th>Designation</th>
|
||||
<th>Nombre</th>
|
||||
<th>Prix unitaire</th>
|
||||
<th>Moyen de paiement</th>
|
||||
<th>Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{% for user in users_list %}
|
||||
{% for facture in facture_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>
|
||||
<td>{{ facture.user }}</td>
|
||||
<td>{{ facture.name }}</td>
|
||||
<td>{{ facture.number }}</td>
|
||||
<td>{{ facture.prix }}</td>
|
||||
<td>{{ facture.paiement }}</td>
|
||||
<td>{{ facture.date }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
|
|
@ -8,6 +8,7 @@ from django.template import Context, RequestContext, loader
|
|||
from django.contrib import messages
|
||||
|
||||
from cotisations.models import NewFactureForm, EditFactureForm, Facture, Article
|
||||
from users.models import User
|
||||
|
||||
def form(ctx, template, request):
|
||||
c = ctx
|
||||
|
@ -15,10 +16,19 @@ def form(ctx, template, request):
|
|||
return render_to_response(template, c, context_instance=RequestContext(request))
|
||||
|
||||
def new_facture(request, userid):
|
||||
facture = Facture.objects.create(user=userid)
|
||||
try:
|
||||
user = User.objects.get(pk=userid)
|
||||
except User.DoesNotExist:
|
||||
messages.error(request, u"Utilisateur inexistant" )
|
||||
return redirect("/cotisations/")
|
||||
facture = Facture(user=user)
|
||||
facture_form = NewFactureForm(request.POST or None, instance=facture)
|
||||
if facture_form.is_valid():
|
||||
facture_form.save()
|
||||
new_facture = facture_form.save(commit=False)
|
||||
article = facture_form.cleaned_data['article']
|
||||
new_facture.prix = article[0].prix
|
||||
new_facture.name = article[0].name
|
||||
new_facture.save()
|
||||
messages.success(request, "La facture a été crée")
|
||||
return redirect("/cotisations/")
|
||||
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
|
||||
|
@ -34,7 +44,7 @@ def edit_facture(request, factureid):
|
|||
facture_form.save()
|
||||
messages.success(request, "La facture a bien été modifiée")
|
||||
return redirect("/cotisations/")
|
||||
return form({'factureform': facture}, 'cotisations/facture.html', request)
|
||||
return form({'factureform': facture_form}, 'cotisations/facture.html', request)
|
||||
|
||||
def index(request):
|
||||
facture_list = Facture.objects.order_by('pk')
|
||||
|
|
Loading…
Reference in a new issue