diff --git a/cotisations/admin.py b/cotisations/admin.py index 58d62fa6..8a17c89a 100644 --- a/cotisations/admin.py +++ b/cotisations/admin.py @@ -6,10 +6,10 @@ class FactureAdmin(admin.ModelAdmin): list_display = ('user','paiement','date','valid','control') class VenteAdmin(admin.ModelAdmin): - list_display = ('facture','name','prix','number','cotisation','duration') + list_display = ('facture','name','prix','number','iscotisation','duration') class ArticleAdmin(admin.ModelAdmin): - list_display = ('name','prix','cotisation','duration') + list_display = ('name','prix','iscotisation','duration') class BanqueAdmin(admin.ModelAdmin): list_display = ('name',) @@ -21,7 +21,7 @@ class PaiementAdmin(admin.ModelAdmin): list_display = ('moyen',) class CotisationAdmin(admin.ModelAdmin): - list_display = ('facture','date_start','date_end') + list_display = ('vente','date_start','date_end') admin.site.register(Facture, FactureAdmin) admin.site.register(Article, ArticleAdmin) diff --git a/cotisations/migrations/0016_auto_20160715_0110.py b/cotisations/migrations/0016_auto_20160715_0110.py new file mode 100644 index 00000000..2dd26439 --- /dev/null +++ b/cotisations/migrations/0016_auto_20160715_0110.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0015_auto_20160714_2142'), + ] + + operations = [ + migrations.RenameField( + model_name='article', + old_name='cotisation', + new_name='iscotisation', + ), + migrations.RenameField( + model_name='vente', + old_name='cotisation', + new_name='iscotisation', + ), + migrations.RemoveField( + model_name='cotisation', + name='facture', + ), + migrations.AddField( + model_name='cotisation', + name='vente', + field=models.OneToOneField(to='cotisations.Vente', null=True), + preserve_default=False, + ), + ] diff --git a/cotisations/models.py b/cotisations/models.py index 71513a42..658f4536 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -1,5 +1,7 @@ from django.db import models +from dateutil.relativedelta import relativedelta +from django.core.validators import MinValueValidator class Facture(models.Model): user = models.ForeignKey('users.User', on_delete=models.PROTECT) @@ -8,6 +10,7 @@ class Facture(models.Model): cheque = models.CharField(max_length=255, blank=True) date = models.DateTimeField(auto_now_add=True) valid = models.BooleanField(default=True) + control = models.BooleanField(default=False) def prix(self): prix = Vente.objects.all().filter(facture=self).aggregate(models.Sum('prix'))['prix__sum'] @@ -24,23 +27,29 @@ class Facture(models.Model): return str(self.date) + ' ' + str(self.user) class Vente(models.Model): - facture = models.ForeignKey('Facture', on_delete=models.PROTECT) - number = models.IntegerField() + facture = models.ForeignKey('Facture', on_delete=models.CASCADE) + number = models.IntegerField(validators=[MinValueValidator(1)]) name = models.CharField(max_length=255) prix = models.DecimalField(max_digits=5, decimal_places=2) - cotisation = models.BooleanField() + iscotisation = models.BooleanField() duration = models.IntegerField(help_text="Durée exprimée en mois entiers", blank=True, null=True) def prix_total(self): return self.prix*self.number + def clean(self): + if hasattr(self, 'cotisation'): + cotisation = self.cotisation + cotisation.date_end = cotisation.date_start + relativedelta(months=self.duration*self.number) + cotisation.save() + def __str__(self): return str(self.name) + ' ' + str(self.facture) class Article(models.Model): name = models.CharField(max_length=255) prix = models.DecimalField(max_digits=5, decimal_places=2) - cotisation = models.BooleanField() + iscotisation = models.BooleanField() duration = models.IntegerField(help_text="Durée exprimée en mois entiers", blank=True, null=True) def __str__(self): @@ -59,10 +68,10 @@ class Paiement(models.Model): return self.moyen class Cotisation(models.Model): - facture = models.OneToOneField('Facture', on_delete=models.PROTECT) + vente = models.OneToOneField('Vente', on_delete=models.CASCADE, null=True) date_start = models.DateTimeField() date_end = models.DateTimeField() def __str__(self): - return str(self.facture) + return str(self.vente) diff --git a/cotisations/templates/cotisations/control.html b/cotisations/templates/cotisations/control.html new file mode 100644 index 00000000..02c6ee41 --- /dev/null +++ b/cotisations/templates/cotisations/control.html @@ -0,0 +1,43 @@ +{% extends "cotisations/sidebar.html" %} +{% load bootstrap3 %} +{% load staticfiles%} + +{% block title %}Controle des factures{% endblock %} + +{% block content %} +