diff --git a/cotisations/admin.py b/cotisations/admin.py
index cbad4542..58d62fa6 100644
--- a/cotisations/admin.py
+++ b/cotisations/admin.py
@@ -3,7 +3,7 @@ from django.contrib import admin
from .models import Facture, Article, Banque, Paiement, Cotisation, Vente
class FactureAdmin(admin.ModelAdmin):
- list_display = ('user','paiement','date','valid')
+ list_display = ('user','paiement','date','valid','control')
class VenteAdmin(admin.ModelAdmin):
list_display = ('facture','name','prix','number','cotisation','duration')
diff --git a/cotisations/forms.py b/cotisations/forms.py
index d9360272..c156fb53 100644
--- a/cotisations/forms.py
+++ b/cotisations/forms.py
@@ -42,13 +42,22 @@ class NewFactureFormPdf(Form):
class EditFactureForm(NewFactureForm):
class Meta(NewFactureForm.Meta):
- fields = '__all__'
+ fields = ['paiement','banque','cheque','user']
def __init__(self, *args, **kwargs):
super(EditFactureForm, self).__init__(*args, **kwargs)
self.fields['user'].label = 'Adherent'
self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire"
+
+class TrezEditFactureForm(EditFactureForm):
+ class Meta(EditFactureForm.Meta):
+ fields = '__all__'
+
+ def __init__(self, *args, **kwargs):
+ super(TrezEditFactureForm, self).__init__(*args, **kwargs)
self.fields['valid'].label = 'Validité de la facture'
+ self.fields['control'].label = 'Controle de la facture'
+
class ArticleForm(ModelForm):
class Meta:
diff --git a/cotisations/migrations/0015_auto_20160714_2142.py b/cotisations/migrations/0015_auto_20160714_2142.py
new file mode 100644
index 00000000..ee677909
--- /dev/null
+++ b/cotisations/migrations/0015_auto_20160714_2142.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import migrations, models
+import django.core.validators
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('cotisations', '0014_auto_20160712_0245'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='facture',
+ name='control',
+ field=models.BooleanField(default=False),
+ ),
+ migrations.AlterField(
+ model_name='cotisation',
+ name='facture',
+ field=models.OneToOneField(to='cotisations.Facture'),
+ ),
+ migrations.AlterField(
+ model_name='vente',
+ name='facture',
+ field=models.ForeignKey(to='cotisations.Facture'),
+ ),
+ migrations.AlterField(
+ model_name='vente',
+ name='number',
+ field=models.IntegerField(validators=[django.core.validators.MinValueValidator(1)]),
+ ),
+ ]
diff --git a/cotisations/templates/cotisations/aff_cotisations.html b/cotisations/templates/cotisations/aff_cotisations.html
index 5638c6ab..0d387ebb 100644
--- a/cotisations/templates/cotisations/aff_cotisations.html
+++ b/cotisations/templates/cotisations/aff_cotisations.html
@@ -17,8 +17,9 @@
{{ facture.prix_total }} |
{{ facture.paiement }} |
{{ facture.date }} |
- {% if is_cableur %} Editer{% endif %} |
- PDF |
+ {% if is_cableur %}{% if facture.valid and not facture.control or is_trez %} Editer{% endif %}{% endif %} |
+ {% if is_cableur %}{% if facture.valid and not facture.control or is_trez %} Supprimer{% else %}Facture controlée{% endif %}{% endif %} |
+ {% if facture.valid %} PDF{% else %}Facture invalide{% endif %} |
{% endfor %}
diff --git a/cotisations/templates/cotisations/facture.html b/cotisations/templates/cotisations/facture.html
index 659c3dce..59c6b2c0 100644
--- a/cotisations/templates/cotisations/facture.html
+++ b/cotisations/templates/cotisations/facture.html
@@ -11,32 +11,10 @@
{% csrf_token %}
{% bootstrap_form factureform %}
{{ venteform.management_form }}
-
{% for form in venteform.forms %}
{{ form.as_p }}
{% endfor %}
-
-
-
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
-
-
-
-
{% endblock %}
diff --git a/cotisations/templates/cotisations/index_article.html b/cotisations/templates/cotisations/index_article.html
index c92fdf8f..dde01575 100644
--- a/cotisations/templates/cotisations/index_article.html
+++ b/cotisations/templates/cotisations/index_article.html
@@ -7,7 +7,7 @@
Liste des types d'articles
{% if is_trez %}
Ajouter un type d'articles
- Supprimer un ou plusieurs types d'articles
+ Supprimer un ou plusieurs types d'articles
{% endif %}
{% include "cotisations/aff_article.html" with article_list=article_list %}
diff --git a/cotisations/urls.py b/cotisations/urls.py
index 24b8dc5a..5587d4c3 100644
--- a/cotisations/urls.py
+++ b/cotisations/urls.py
@@ -5,6 +5,7 @@ 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'^del_facture/(?P[0-9]+)$', views.del_facture, name='del-facture'),
url(r'^facture_pdf/(?P[0-9]+)$', views.facture_pdf, name='facture-pdf'),
url(r'^new_facture_pdf/$', views.new_facture_pdf, name='new-facture-pdf'),
url(r'^add_article/$', views.add_article, name='add-article'),
diff --git a/cotisations/views.py b/cotisations/views.py
index 516da18c..6b9e86cb 100644
--- a/cotisations/views.py
+++ b/cotisations/views.py
@@ -12,7 +12,7 @@ from django.forms import modelformset_factory, formset_factory
import os
from .models import Facture, Article, Vente, Cotisation, Paiement, Banque
-from .forms import NewFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, SelectArticleForm
+from .forms import NewFactureForm, TrezEditFactureForm, EditFactureForm, ArticleForm, DelArticleForm, PaiementForm, DelPaiementForm, BanqueForm, DelBanqueForm, NewFactureFormPdf, SelectArticleForm
from users.models import User
from .tex import render_tex
from re2o.settings_local import ASSO_NAME, ASSO_ADDRESS_LINE1, ASSO_ADDRESS_LINE2, ASSO_SIRET, ASSO_EMAIL, ASSO_PHONE, LOGO_PATH
@@ -104,6 +104,9 @@ def facture_pdf(request, factureid):
if not request.user.has_perms(('cableur',)) and facture.user != request.user:
messages.error(request, "Vous ne pouvez pas afficher une facture ne vous appartenant pas sans droit cableur")
return redirect("/users/profil/" + str(request.user.id))
+ if not facture.valid:
+ messages.error(request, "Vous ne pouvez pas afficher une facture non valide")
+ return redirect("/users/profil/" + str(request.user.id))
vente = Vente.objects.all().filter(facture=facture)
ventes = []
for v in vente:
@@ -118,7 +121,13 @@ def edit_facture(request, factureid):
except Facture.DoesNotExist:
messages.error(request, u"Facture inexistante" )
return redirect("/cotisations/")
- facture_form = EditFactureForm(request.POST or None, instance=facture)
+ if request.user.has_perms(['trésorier']):
+ facture_form = TrezEditFactureForm(request.POST or None, instance=facture)
+ elif facture.control or not facture.valid:
+ messages.error(request, "Vous ne pouvez pas editer une facture controlée ou invalidée par le trésorier")
+ return redirect("/cotisations/")
+ else:
+ facture_form = EditFactureForm(request.POST or None, instance=facture)
ventes_objects = Vente.objects.filter(facture=facture)
vente_form_set = modelformset_factory(Vente, fields=('name','number'), extra=0, max_num=len(ventes_objects))
vente_form = vente_form_set(request.POST or None, queryset=ventes_objects)
@@ -129,6 +138,21 @@ def edit_facture(request, factureid):
return redirect("/cotisations/")
return form({'factureform': facture_form, 'venteform': vente_form}, 'cotisations/facture.html', request)
+@login_required
+@permission_required('cableur')
+def del_facture(request, factureid):
+ try:
+ facture = Facture.objects.get(pk=factureid)
+ except Facture.DoesNotExist:
+ messages.error(request, u"Facture inexistante" )
+ return redirect("/cotisations/")
+ if (facture.control or not facture.valid):
+ messages.error(request, "Vous ne pouvez pas editer une facture controlée ou invalidée par le trésorier")
+ return redirect("/cotisations/")
+ facture.delete()
+ messages.success(request, "La facture a bien été supprimée")
+ return redirect("/cotisations/")
+
@login_required
@permission_required('trésorier')
def add_article(request):