Commit f08a42a3 authored by chirac's avatar chirac

Creer un champ controle, permet d'editer et de supprimer une facture tant que non controlée

parent 0f1a5a82
......@@ -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')
......
......@@ -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:
......
# -*- 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)]),
),
]
......@@ -17,8 +17,9 @@
<td>{{ facture.prix_total }}</td>
<td>{{ facture.paiement }}</td>
<td>{{ facture.date }}</td>
<td>{% if is_cableur %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-facture' facture.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Editer</a>{% endif %}</td>
<td><a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:facture-pdf' facture.id %}"><i class="glyphicon glyphicon-save"></i> PDF</a></td>
<td>{% if is_cableur %}{% if facture.valid and not facture.control or is_trez %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:edit-facture' facture.id %}"><i class="glyphicon glyphicon-bitcoin"></i> Editer</a>{% endif %}{% endif %}</td>
<td>{% if is_cableur %}{% if facture.valid and not facture.control or is_trez %}<a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:del-facture' facture.id %}"><i class="glyphicon glyphicon-trash"></i> Supprimer</a>{% else %}Facture controlée{% endif %}{% endif %}</td>
<td>{% if facture.valid %}<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:facture-pdf' facture.id %}"><i class="glyphicon glyphicon-save"></i> PDF</a>{% else %}Facture invalide{% endif %}</td>
</tr>
{% endfor %}
</table>
......
......@@ -11,32 +11,10 @@
{% csrf_token %}
{% bootstrap_form factureform %}
{{ venteform.management_form }}
<div id="form_set">
{% for form in venteform.forms %}
{{ form.as_p }}
{% endfor %}
</div>
<input class="btn btn-primary btn-sm" role="button" value="Ajouter un article" id="add_one">
<input class="btn btn-primary btn-sm" role="button" value="Supprimer un article" id="del_one">
{% bootstrap_button "Créer ou modifier" button_type="submit" icon="star" %}
</form>
<div id="empty_form" style="display:none">
<table class='no_error'>
{{ venteform.empty_form.as_p }}
</table>
</div>
<script>
$('#add_one').click(function() {
var form_idx = $('#id_form-TOTAL_FORMS').val();
$('#form_set').append($('#empty_form').html().replace(/__prefix__/g, form_idx));
$('#id_form-TOTAL_FORMS').val(parseInt(form_idx) + 1);
});
$('#del_one').click(function() {
var forms = $('.dynamic-form');
$('#id_form-TOTAL_FORMS').val(forms.length);
});
</script>
{% endblock %}
......@@ -7,7 +7,7 @@
<h2>Liste des types d'articles</h2>
{% if is_trez %}
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:add-article' %}"><i class="glyphicon glyphicon-plus"></i> Ajouter un type d'articles</a>
<a class="btn btn-primary btn-sm" role="button" href="{% url 'cotisations:del-article' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types d'articles</a>
<a class="btn btn-danger btn-sm" role="button" href="{% url 'cotisations:del-article' %}"><i class="glyphicon glyphicon-trash"></i> Supprimer un ou plusieurs types d'articles</a>
{% endif %}
{% include "cotisations/aff_article.html" with article_list=article_list %}
<br />
......
......@@ -5,6 +5,7 @@ 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'^del_facture/(?P<factureid>[0-9]+)$', views.del_facture, name='del-facture'),
url(r'^facture_pdf/(?P<factureid>[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'),
......
......@@ -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):
......
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