Commit 7a34a672 authored by Gabriel Detraz's avatar Gabriel Detraz

Ajoute la possibilite de faire des credits

parent 78d536a2
...@@ -36,3 +36,11 @@ class DelPaiementForm(ModelForm): ...@@ -36,3 +36,11 @@ class DelPaiementForm(ModelForm):
exclude = ['moyen'] exclude = ['moyen']
model = Paiement model = Paiement
class CreditForm(ModelForm):
class Meta:
model = Credit
fields = ['montant','moyen','validite']
class CreditFullForm(CreditForm):
class Meta(CreditForm.Meta):
fields = '__all__'
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('panier', '0002_auto_20160904_1526'),
]
operations = [
migrations.AlterField(
model_name='credit',
name='validite',
field=models.BooleanField(default=True),
),
migrations.AlterField(
model_name='livraison',
name='date',
field=models.DateTimeField(help_text='%d/%m/%y %H:%M:%S'),
),
]
...@@ -21,10 +21,10 @@ class Credit(models.Model): ...@@ -21,10 +21,10 @@ class Credit(models.Model):
user = models.ForeignKey('users.User', on_delete=models.PROTECT) user = models.ForeignKey('users.User', on_delete=models.PROTECT)
montant = models.DecimalField(max_digits=5, decimal_places=2) montant = models.DecimalField(max_digits=5, decimal_places=2)
moyen = models.ForeignKey('Paiement', on_delete=models.PROTECT) moyen = models.ForeignKey('Paiement', on_delete=models.PROTECT)
validite = models.BooleanField() validite = models.BooleanField(default=True)
def __str__(self): def __str__(self):
return self.montant return str(self.montant) + str(self.user)
class Paiement(models.Model): class Paiement(models.Model):
moyen = models.CharField(max_length=255, unique=True) moyen = models.CharField(max_length=255, unique=True)
......
...@@ -63,6 +63,8 @@ ...@@ -63,6 +63,8 @@
<th>Montant</th> <th>Montant</th>
<th>Mode de reglement</th> <th>Mode de reglement</th>
<th>Validité</th> <th>Validité</th>
<th></th>
<th></th>
</tr> </tr>
</thead> </thead>
{% for credit in credit_list %} {% for credit in credit_list %}
...@@ -71,7 +73,19 @@ ...@@ -71,7 +73,19 @@
<td>{{ credit.user.surname }}</td> <td>{{ credit.user.surname }}</td>
<td>{{ credit.montant }}</td> <td>{{ credit.montant }}</td>
<td>{{ credit.moyen }}</td> <td>{{ credit.moyen }}</td>
<td>{{ credit.validite }}</td> <td>{{ credit.validite }}</td>
{% if is_bureau %}
<td><div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="editioncredit" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
Modifier
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="editionfacture">
<li><a href="{% url 'panier:edit-credit' credit.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Editer</a></li>
<li><a href="{% url 'panier:del-credit' credit.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a></li>
</ul></div></td>
{% endif %}
<td><a class="btn btn-info btn-sm" role="button" href="{% url 'panier:history' 'credit' credit.id %}"><i class="glyphicon glyphicon-repeat"></i> Historique</a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>
{% extends "panier/sidebar.html" %}
{% load bootstrap3 %}
{% block title %}Création et modificatio nde commandes et de credits {% endblock %}
{% block content %}
<form class="form" method="post">
{% csrf_token %}
<h4>Attention, voulez-vous vraiment supprimer cet objet {{ objet_name }} ( {{ objet }} ) ?</h4>
{% bootstrap_button "Confirmer" button_type="submit" icon="trash" %}
</form>
<br />
<br />
<br />
{% endblock %}
...@@ -11,8 +11,12 @@ urlpatterns = [ ...@@ -11,8 +11,12 @@ urlpatterns = [
url(r'^edit_livraison/(?P<livraisonid>[0-9]+)$', views.edit_livraison, name='edit-livraison'), url(r'^edit_livraison/(?P<livraisonid>[0-9]+)$', views.edit_livraison, name='edit-livraison'),
url(r'^del_livraison/$', views.del_livraison, name='del-livraison'), url(r'^del_livraison/$', views.del_livraison, name='del-livraison'),
url(r'^index_livraison/$', views.index_livraison, name='index-livraison'), url(r'^index_livraison/$', views.index_livraison, name='index-livraison'),
url(r'^add_credit/(?P<userid>[0-9]+)$', views.add_credit, name='add-credit'),
url(r'^edit_credit/(?P<creditid>[0-9]+)$', views.edit_credit, name='edit-credit'),
url(r'^del_credit/(?P<creditid>[0-9]+)$', views.del_credit, name='del-credit'),
url(r'^history/(?P<object>paiement)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^history/(?P<object>paiement)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>livraison)/(?P<id>[0-9]+)$', views.history, name='history'), url(r'^history/(?P<object>livraison)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^history/(?P<object>credit)/(?P<id>[0-9]+)$', views.history, name='history'),
url(r'^$', views.index, name='index'), url(r'^$', views.index, name='index'),
] ]
......
...@@ -14,7 +14,9 @@ from django.contrib.auth.decorators import login_required, permission_required ...@@ -14,7 +14,9 @@ from django.contrib.auth.decorators import login_required, permission_required
from django.db import transaction from django.db import transaction
from reversion import revisions as reversion from reversion import revisions as reversion
from .models import Panier, Paiement, Commande, Credit, Livraison from .models import Panier, Paiement, Commande, Credit, Livraison
from .forms import PaiementForm, DelPaiementForm, LivraisonForm, DelLivraisonForm from .forms import PaiementForm, CreditForm, CreditFullForm, DelPaiementForm, LivraisonForm, DelLivraisonForm
from users.views import User
from amap.settings import PAGINATION_NUMBER from amap.settings import PAGINATION_NUMBER
...@@ -127,9 +129,72 @@ def del_paiement(request): ...@@ -127,9 +129,72 @@ def del_paiement(request):
return redirect("/panier/index_paiement/") return redirect("/panier/index_paiement/")
return form({'panierform': paiement}, 'panier/panier.html', request) return form({'panierform': paiement}, 'panier/panier.html', request)
@login_required
@permission_required('bureau')
def add_credit(request, userid):
try:
user = User.objects.get(pk=userid)
except User.DoesNotExist:
messages.error(request, "Utilisateur inexistant")
return redirect("/panier/")
credit = CreditForm(request.POST or None)
if credit.is_valid():
credit = credit.save(commit=False)
credit.user = user
with transaction.atomic(), reversion.create_revision():
credit.save()
reversion.set_user(request.user)
reversion.set_comment("Creation")
messages.success(request, "Le credit a ete ajoute")
return redirect("/panier/")
return form({'panierform': credit}, 'panier/panier.html', request)
@login_required
@permission_required('bureau')
def edit_credit(request, creditid):
try:
credit_instance = Credit.objects.get(pk=creditid)
except Credit.DoesNotExist:
messages.error(request, u"Entrée inexistante" )
return redirect("/panier/")
credit = CreditFullForm(request.POST or None, instance=credit_instance)
if credit.is_valid():
with transaction.atomic(), reversion.create_revision():
credit.save()
reversion.set_user(request.user)
reversion.set_comment("Champs modifié(s) : %s" % ', '.join(field for field in credit.changed_data))
messages.success(request, "Date modifiee")
return redirect("/panier/")
return form({'panierform': credit}, 'panier/panier.html', request)
@login_required
@permission_required('bureau')
def del_credit(request, creditid):
try:
credit = Credit.objects.get(pk=creditid)
except Credit.DoesNotExist:
messages.error(request, u"Credit inexistant" )
return redirect("/panier/")
if request.method == "POST":
with transaction.atomic(), reversion.create_revision():
credit.delete()
reversion.set_user(request.user)
messages.success(request, "Le credit a été détrite")
return redirect("/panier/")
return form({'objet': credit, 'objet_name': 'credit'}, 'panier/delete.html', request)
@login_required @login_required
def history(request, object, id): def history(request, object, id):
if object == 'paiement' and request.user.has_perms(('cableur',)): if object == 'credit':
try:
object_instance = Credit.objects.get(pk=id)
except Credit.DoesNotExist:
messages.error(request, "Credit inexistant")
return redirect("/panier/")
if not request.user.has_perms(('bureau',)) and object_instance.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher l'historique d'une facture d'un autre user que vous sans droit ")
return redirect("/panier/")
elif object == 'paiement' and request.user.has_perms(('bureau',)):
try: try:
object_instance = Paiement.objects.get(pk=id) object_instance = Paiement.objects.get(pk=id)
except Paiement.DoesNotExist: except Paiement.DoesNotExist:
...@@ -188,13 +253,13 @@ def index(request): ...@@ -188,13 +253,13 @@ def index(request):
return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'credit_list': credit_list}) return render(request, 'panier/index.html', {'paniers_list': paniers_list, 'credit_list': credit_list})
@login_required @login_required
@permission_required('cableur') @permission_required('bureau')
def index_paiement(request): def index_paiement(request):
paiement_list = Paiement.objects.order_by('moyen') paiement_list = Paiement.objects.order_by('moyen')
return render(request, 'panier/index_paiement.html', {'paiement_list':paiement_list}) return render(request, 'panier/index_paiement.html', {'paiement_list':paiement_list})
@login_required @login_required
@permission_required('cableur') @permission_required('bureau')
def index_livraison(request): def index_livraison(request):
livraison_list = Livraison.objects.order_by('date') livraison_list = Livraison.objects.order_by('date')
return render(request, 'panier/index_livraison.html', {'livraison_list':livraison_list}) return render(request, 'panier/index_livraison.html', {'livraison_list':livraison_list})
...@@ -65,8 +65,15 @@ ...@@ -65,8 +65,15 @@
</tr> </tr>
<tr> <tr>
</table> </table>
<br />
<br /> <h2>Commandes et crédits</h2>
<br /> {% if is_bureau %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'panier:add-credit' user.id %}"><i class="glyphicon glyphicon-piggy-bank"></i> Enregistrer un crédit</a>{% endif %}
<br/>
{% include "panier/aff_paniers.html" %}
<br/>
<br/>
<br/>
{% endblock %} {% endblock %}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment