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

Fonction de création et d'edition de factures parfaitement fonctionnelle

This commit is contained in:
chirac 2016-07-02 17:58:04 +02:00
parent 1c5070fc82
commit 2155d46877
20 changed files with 178 additions and 20 deletions

View file

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

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 = [
('cotisations', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='facture',
name='article',
),
]

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

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

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', '0004_auto_20160702_1528'),
]
operations = [
migrations.AlterField(
model_name='facture',
name='cheque',
field=models.CharField(max_length=255, blank=True),
),
]

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

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

View file

@ -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__'

View file

@ -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 %}

View file

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

View file

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