2016-07-02 13:58:50 +00:00
|
|
|
from django.db import models
|
|
|
|
from django import forms
|
|
|
|
from django.forms import ModelForm
|
|
|
|
|
|
|
|
from users.models import User
|
|
|
|
|
|
|
|
class Facture(models.Model):
|
|
|
|
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
|
|
|
|
paiement = models.ForeignKey('Paiement', on_delete=models.PROTECT)
|
2016-07-02 15:58:04 +00:00
|
|
|
banque = models.ForeignKey('Banque', on_delete=models.PROTECT, blank=True, null=True)
|
|
|
|
cheque = models.CharField(max_length=255, blank=True)
|
2016-07-02 13:58:50 +00:00
|
|
|
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)
|
2016-07-02 16:30:59 +00:00
|
|
|
valid = models.BooleanField(default=True)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2016-07-02 16:30:59 +00:00
|
|
|
return str(self.name) + ' ' + str(self.date) + ' ' + str(self.user)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
|
|
|
class Article(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
prix = models.DecimalField(max_digits=5, decimal_places=2)
|
2016-07-02 16:30:59 +00:00
|
|
|
cotisation = models.BooleanField()
|
2016-07-02 19:17:21 +00:00
|
|
|
duration = models.IntegerField(help_text="Durée exprimée en mois entiers", blank=True, null=True)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Banque(models.Model):
|
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
|
|
|
class Paiement(models.Model):
|
|
|
|
moyen = models.CharField(max_length=255)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.moyen
|
|
|
|
|
2016-07-02 16:30:59 +00:00
|
|
|
class Cotisation(models.Model):
|
2016-07-04 01:21:25 +00:00
|
|
|
facture = models.OneToOneField('Facture', on_delete=models.PROTECT)
|
2016-07-02 19:17:21 +00:00
|
|
|
date_start = models.DateTimeField()
|
2016-07-02 16:30:59 +00:00
|
|
|
date_end = models.DateTimeField()
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return str(self.facture)
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
class NewFactureForm(ModelForm):
|
|
|
|
article = forms.ModelMultipleChoiceField(queryset=Article.objects.all(), label="Article")
|
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(NewFactureForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['number'].label = 'Quantité'
|
|
|
|
self.fields['cheque'].required = False
|
|
|
|
self.fields['banque'].required = False
|
|
|
|
self.fields['cheque'].label = 'Numero de chèque'
|
2016-07-05 09:33:27 +00:00
|
|
|
self.fields['banque'].empty_label = "Non renseigné"
|
|
|
|
self.fields['paiement'].empty_label = "Séléctionner un moyen de paiement"
|
2016-07-02 13:58:50 +00:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Facture
|
2016-07-05 09:51:29 +00:00
|
|
|
fields = ['paiement','banque','cheque','number']
|
|
|
|
|
2016-07-05 12:01:29 +00:00
|
|
|
def clean(self):
|
|
|
|
cleaned_data=super(NewFactureForm, self).clean()
|
|
|
|
paiement = cleaned_data.get("paiement")
|
|
|
|
cheque = cleaned_data.get("cheque")
|
|
|
|
banque = cleaned_data.get("banque")
|
|
|
|
if paiement.moyen=="chèque" and not (cheque and banque):
|
|
|
|
raise forms.ValidationError("Le numero de chèque et la banque sont obligatoires")
|
|
|
|
return cleaned_data
|
|
|
|
|
2016-07-05 09:51:29 +00:00
|
|
|
class EditFactureForm(NewFactureForm):
|
|
|
|
class Meta(NewFactureForm.Meta):
|
|
|
|
fields = '__all__'
|
2016-07-02 13:58:50 +00:00
|
|
|
|
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(EditFactureForm, self).__init__(*args, **kwargs)
|
|
|
|
self.fields['user'].label = 'Adherent'
|
|
|
|
self.fields['name'].label = 'Designation'
|
|
|
|
self.fields['prix'].label = 'Prix unitaire'
|
2016-07-05 09:33:27 +00:00
|
|
|
self.fields['user'].empty_label = "Séléctionner l'adhérent propriétaire"
|
2016-07-05 09:51:29 +00:00
|
|
|
self.fields.pop('article')
|