2017-09-10 14:53:02 +00:00
|
|
|
# -*- mode: python; coding: utf-8 -*-
|
2017-01-15 23:01:18 +00:00
|
|
|
# Re2o est un logiciel d'administration développé initiallement au rezometz. Il
|
|
|
|
# se veut agnostique au réseau considéré, de manière à être installable en
|
|
|
|
# quelques clics.
|
|
|
|
#
|
|
|
|
# Copyright © 2017 Gabriel Détraz
|
|
|
|
# Copyright © 2017 Goulven Kermarec
|
|
|
|
# Copyright © 2017 Augustin Lemesle
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2017-10-13 21:15:07 +00:00
|
|
|
"""
|
|
|
|
Definition des models bdd pour les factures et cotisation.
|
|
|
|
Pièce maitresse : l'ensemble du code intelligent se trouve ici,
|
|
|
|
dans les clean et save des models ainsi que de leur methodes supplémentaires.
|
|
|
|
|
|
|
|
Facture : reliée à un user, elle a un moyen de paiement, une banque (option),
|
|
|
|
une ou plusieurs ventes
|
|
|
|
|
|
|
|
Article : liste des articles en vente, leur prix, etc
|
|
|
|
|
|
|
|
Vente : ensemble des ventes effectuées, reliées à une facture (foreignkey)
|
|
|
|
|
|
|
|
Banque : liste des banques existantes
|
|
|
|
|
|
|
|
Cotisation : objets de cotisation, contenant un début et une fin. Reliées
|
|
|
|
aux ventes, en onetoone entre une vente et une cotisation.
|
|
|
|
Crées automatiquement au save des ventes.
|
|
|
|
|
|
|
|
Post_save et Post_delete : sychronisation des services et régénération
|
|
|
|
des services d'accès réseau (ex dhcp) lors de la vente d'une cotisation
|
|
|
|
par exemple
|
|
|
|
"""
|
2017-01-15 23:01:18 +00:00
|
|
|
|
2017-09-10 23:29:24 +00:00
|
|
|
from __future__ import unicode_literals
|
2017-10-13 21:15:07 +00:00
|
|
|
from dateutil.relativedelta import relativedelta
|
2017-09-10 23:29:24 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
from django.db import models
|
2017-10-29 17:48:30 +00:00
|
|
|
from django.db.models import Q
|
2016-07-25 22:13:38 +00:00
|
|
|
from django.db.models.signals import post_save, post_delete
|
|
|
|
from django.dispatch import receiver
|
2017-06-26 17:23:01 +00:00
|
|
|
from django.forms import ValidationError
|
2016-07-17 18:08:56 +00:00
|
|
|
from django.core.validators import MinValueValidator
|
2017-09-27 13:40:28 +00:00
|
|
|
from django.db.models import Max
|
2017-07-24 00:33:38 +00:00
|
|
|
from django.utils import timezone
|
2017-09-01 01:15:54 +00:00
|
|
|
from machines.models import regen
|
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
class Facture(models.Model):
|
2017-10-13 02:07:56 +00:00
|
|
|
""" Définition du modèle des factures. Une facture regroupe une ou
|
|
|
|
plusieurs ventes, rattachée à un user, et reliée à un moyen de paiement
|
|
|
|
et si il y a lieu un numero pour les chèques. Possède les valeurs
|
|
|
|
valides et controle (trésorerie)"""
|
2016-11-01 01:14:06 +00:00
|
|
|
PRETTY_NAME = "Factures émises"
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
user = models.ForeignKey('users.User', on_delete=models.PROTECT)
|
|
|
|
paiement = models.ForeignKey('Paiement', on_delete=models.PROTECT)
|
2017-10-13 02:07:56 +00:00
|
|
|
banque = models.ForeignKey(
|
2017-10-13 21:15:07 +00:00
|
|
|
'Banque',
|
|
|
|
on_delete=models.PROTECT,
|
|
|
|
blank=True,
|
|
|
|
null=True)
|
2016-07-02 15:58:04 +00:00
|
|
|
cheque = models.CharField(max_length=255, blank=True)
|
2016-07-02 13:58:50 +00:00
|
|
|
date = models.DateTimeField(auto_now_add=True)
|
2016-07-11 20:52:55 +00:00
|
|
|
valid = models.BooleanField(default=True)
|
2016-07-17 18:08:56 +00:00
|
|
|
control = models.BooleanField(default=False)
|
2016-07-11 20:52:55 +00:00
|
|
|
|
|
|
|
def prix(self):
|
2017-10-13 21:15:07 +00:00
|
|
|
"""Renvoie le prix brut sans les quantités. Méthode
|
|
|
|
dépréciée"""
|
2017-10-13 02:07:56 +00:00
|
|
|
prix = Vente.objects.filter(
|
2017-10-13 21:15:07 +00:00
|
|
|
facture=self
|
|
|
|
).aggregate(models.Sum('prix'))['prix__sum']
|
2016-07-11 20:52:55 +00:00
|
|
|
return prix
|
|
|
|
|
2016-07-11 22:05:07 +00:00
|
|
|
def prix_total(self):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Prix total : somme des produits prix_unitaire et quantité des
|
|
|
|
ventes de l'objet"""
|
|
|
|
return Vente.objects.filter(
|
2017-10-13 21:15:07 +00:00
|
|
|
facture=self
|
|
|
|
).aggregate(
|
2017-10-13 02:07:56 +00:00
|
|
|
total=models.Sum(
|
|
|
|
models.F('prix')*models.F('number'),
|
|
|
|
output_field=models.FloatField()
|
2017-10-13 21:15:07 +00:00
|
|
|
)
|
|
|
|
)['total']
|
2016-07-11 22:05:07 +00:00
|
|
|
|
2016-07-11 20:52:55 +00:00
|
|
|
def name(self):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""String, somme des name des ventes de self"""
|
|
|
|
name = ' - '.join(Vente.objects.filter(
|
|
|
|
facture=self
|
|
|
|
).values_list('name', flat=True))
|
2016-07-11 20:52:55 +00:00
|
|
|
return name
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def get_instance(factureid, *args, **kwargs):
|
|
|
|
return Facture.objects.get(pk=factureid)
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit de créer des factures"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_edit_all(user_request, *args, **kwargs):
|
|
|
|
if not user_request.has_perms(('cableur',)):
|
|
|
|
return False, u"Vous n'avez pas le droit d'éditer les factures"
|
|
|
|
return None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
|
|
|
if not user_request.has_perms(('cableur',)):
|
|
|
|
return False, u"Vous n'avez pas le droit d'éditer les factures"
|
|
|
|
elif not user_request.has_perms(('tresorier',)) and\
|
|
|
|
(self.control or not self.valid):
|
|
|
|
return False, u"Vous n'avez pas le droit d'éditer une facture\
|
|
|
|
controlée ou invalidée par un trésorier"
|
|
|
|
else:
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_delete_all(user_request, *args, **kwargs):
|
|
|
|
if not user_request.has_perms(('cableur',)):
|
|
|
|
return False, u"Vous n'avez pas le droit de supprimer une facture"
|
|
|
|
return None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
|
|
|
if not user_request.has_perms(('cableur',)):
|
|
|
|
return False, u"Vous n'avez pas le droit de supprimer une facture"
|
|
|
|
if self.control or not self.valid:
|
|
|
|
return False, u"Vous ne pouvez pas supprimer une facture\
|
|
|
|
contrôlée ou invalidée par un trésorier"
|
|
|
|
else:
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
|
|
|
if not user_request.has_perms(('cableur',)) and\
|
|
|
|
self.user != user_request:
|
|
|
|
return False, u"Vous ne pouvez pas afficher l'historique d'une\
|
|
|
|
facture d'un autre user que vous sans droit cableur"
|
|
|
|
else:
|
|
|
|
return True, None
|
|
|
|
|
2016-07-11 20:52:55 +00:00
|
|
|
def __str__(self):
|
2017-01-08 12:41:01 +00:00
|
|
|
return str(self.user) + ' ' + str(self.date)
|
2016-07-11 20:52:55 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-25 22:13:38 +00:00
|
|
|
@receiver(post_save, sender=Facture)
|
|
|
|
def facture_post_save(sender, **kwargs):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Post save d'une facture, synchronise l'user ldap"""
|
2016-07-25 22:13:38 +00:00
|
|
|
facture = kwargs['instance']
|
|
|
|
user = facture.user
|
2016-11-20 15:53:59 +00:00
|
|
|
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
2016-07-25 22:13:38 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-25 22:13:38 +00:00
|
|
|
@receiver(post_delete, sender=Facture)
|
|
|
|
def facture_post_delete(sender, **kwargs):
|
2017-10-13 21:15:07 +00:00
|
|
|
"""Après la suppression d'une facture, on synchronise l'user ldap"""
|
2016-07-25 22:13:38 +00:00
|
|
|
user = kwargs['instance'].user
|
2016-11-20 15:53:59 +00:00
|
|
|
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
2016-07-25 22:13:38 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-11 20:52:55 +00:00
|
|
|
class Vente(models.Model):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Objet vente, contient une quantité, une facture parente, un nom,
|
|
|
|
un prix. Peut-être relié à un objet cotisation, via le boolean
|
|
|
|
iscotisation"""
|
2016-11-01 01:14:06 +00:00
|
|
|
PRETTY_NAME = "Ventes effectuées"
|
|
|
|
|
2017-10-28 02:59:40 +00:00
|
|
|
COTISATION_TYPE = (
|
|
|
|
('Connexion', 'Connexion'),
|
|
|
|
('Adhesion', 'Adhesion'),
|
|
|
|
('All', 'All'),
|
|
|
|
)
|
|
|
|
|
2016-07-17 18:08:56 +00:00
|
|
|
facture = models.ForeignKey('Facture', on_delete=models.CASCADE)
|
|
|
|
number = models.IntegerField(validators=[MinValueValidator(1)])
|
2016-07-02 13:58:50 +00:00
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
prix = models.DecimalField(max_digits=5, decimal_places=2)
|
2017-10-15 18:37:21 +00:00
|
|
|
duration = models.PositiveIntegerField(
|
2017-10-13 21:15:07 +00:00
|
|
|
help_text="Durée exprimée en mois entiers",
|
|
|
|
blank=True,
|
|
|
|
null=True)
|
2017-10-28 02:59:40 +00:00
|
|
|
type_cotisation = models.CharField(
|
|
|
|
choices=COTISATION_TYPE,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
max_length=255
|
|
|
|
)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2016-07-14 11:55:46 +00:00
|
|
|
def prix_total(self):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Renvoie le prix_total de self (nombre*prix)"""
|
2016-07-14 11:55:46 +00:00
|
|
|
return self.prix*self.number
|
|
|
|
|
2017-07-24 00:33:38 +00:00
|
|
|
def update_cotisation(self):
|
2017-10-13 21:15:07 +00:00
|
|
|
"""Mets à jour l'objet related cotisation de la vente, si
|
|
|
|
il existe : update la date de fin à partir de la durée de
|
|
|
|
la vente"""
|
2016-07-17 18:08:56 +00:00
|
|
|
if hasattr(self, 'cotisation'):
|
|
|
|
cotisation = self.cotisation
|
2017-10-13 02:07:56 +00:00
|
|
|
cotisation.date_end = cotisation.date_start + relativedelta(
|
2017-10-13 21:15:07 +00:00
|
|
|
months=self.duration*self.number)
|
2017-07-24 00:33:38 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def create_cotis(self, date_start=False):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Update et crée l'objet cotisation associé à une facture, prend
|
|
|
|
en argument l'user, la facture pour la quantitéi, et l'article pour
|
|
|
|
la durée"""
|
2017-10-28 02:59:40 +00:00
|
|
|
if not hasattr(self, 'cotisation') and self.type_cotisation:
|
2017-10-13 02:07:56 +00:00
|
|
|
cotisation = Cotisation(vente=self)
|
2017-10-28 02:59:40 +00:00
|
|
|
cotisation.type_cotisation = self.type_cotisation
|
2017-07-24 00:33:38 +00:00
|
|
|
if date_start:
|
2017-10-29 17:48:30 +00:00
|
|
|
end_cotisation = Cotisation.objects.filter(
|
2017-10-13 21:15:07 +00:00
|
|
|
vente__in=Vente.objects.filter(
|
|
|
|
facture__in=Facture.objects.filter(
|
|
|
|
user=self.facture.user
|
|
|
|
).exclude(valid=False))
|
2017-10-28 02:59:40 +00:00
|
|
|
).filter(Q(type_cotisation='All') | Q(type_cotisation=self.type_cotisation)
|
2017-10-13 21:15:07 +00:00
|
|
|
).filter(
|
2017-10-13 02:07:56 +00:00
|
|
|
date_start__lt=date_start
|
2017-10-13 21:15:07 +00:00
|
|
|
).aggregate(Max('date_end'))['date_end__max']
|
2017-10-28 02:59:40 +00:00
|
|
|
elif self.type_cotisation=="Adhesion":
|
|
|
|
end_cotisation = self.facture.user.end_adhesion()
|
2017-07-24 00:33:38 +00:00
|
|
|
else:
|
2017-10-28 02:59:40 +00:00
|
|
|
end_cotisation = self.facture.user.end_connexion()
|
2017-07-24 00:33:38 +00:00
|
|
|
date_start = date_start or timezone.now()
|
2017-10-28 02:59:40 +00:00
|
|
|
end_cotisation = end_cotisation or date_start
|
|
|
|
date_max = max(end_cotisation, date_start)
|
2017-07-24 00:33:38 +00:00
|
|
|
cotisation.date_start = date_max
|
2017-10-13 02:07:56 +00:00
|
|
|
cotisation.date_end = cotisation.date_start + relativedelta(
|
2017-10-13 21:15:07 +00:00
|
|
|
months=self.duration*self.number
|
|
|
|
)
|
2017-07-24 00:33:38 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
def save(self, *args, **kwargs):
|
|
|
|
# On verifie que si iscotisation, duration est présent
|
2017-10-28 02:59:40 +00:00
|
|
|
if self.type_cotisation and not self.duration:
|
2017-10-13 02:07:56 +00:00
|
|
|
raise ValidationError("Cotisation et durée doivent être présents\
|
|
|
|
ensembles")
|
2017-07-24 00:33:38 +00:00
|
|
|
self.update_cotisation()
|
|
|
|
super(Vente, self).save(*args, **kwargs)
|
2016-07-17 18:08:56 +00:00
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def get_instance(venteid, *args, **kwargs):
|
|
|
|
return Vente.objects.get(pk=venteid)
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_edit_all(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_delete_all(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
def __str__(self):
|
2016-07-11 20:52:55 +00:00
|
|
|
return str(self.name) + ' ' + str(self.facture)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-25 22:13:38 +00:00
|
|
|
@receiver(post_save, sender=Vente)
|
|
|
|
def vente_post_save(sender, **kwargs):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Post save d'une vente, déclencge la création de l'objet cotisation
|
|
|
|
si il y a lieu(si iscotisation) """
|
2016-07-25 22:13:38 +00:00
|
|
|
vente = kwargs['instance']
|
2017-09-27 15:50:11 +00:00
|
|
|
if hasattr(vente, 'cotisation'):
|
|
|
|
vente.cotisation.vente = vente
|
|
|
|
vente.cotisation.save()
|
2017-10-28 02:59:40 +00:00
|
|
|
if vente.type_cotisation:
|
2017-07-24 00:33:38 +00:00
|
|
|
vente.create_cotis()
|
2017-09-27 15:50:11 +00:00
|
|
|
vente.cotisation.save()
|
2016-07-25 22:13:38 +00:00
|
|
|
user = vente.facture.user
|
2016-11-20 15:53:59 +00:00
|
|
|
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
2016-07-25 22:13:38 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-25 22:13:38 +00:00
|
|
|
@receiver(post_delete, sender=Vente)
|
|
|
|
def vente_post_delete(sender, **kwargs):
|
2017-10-13 21:15:07 +00:00
|
|
|
"""Après suppression d'une vente, on synchronise l'user ldap (ex
|
|
|
|
suppression d'une cotisation"""
|
2016-07-25 22:13:38 +00:00
|
|
|
vente = kwargs['instance']
|
2017-10-28 02:59:40 +00:00
|
|
|
if vente.type_cotisation:
|
2016-07-25 22:13:38 +00:00
|
|
|
user = vente.facture.user
|
2016-11-20 15:53:59 +00:00
|
|
|
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
2016-07-25 22:13:38 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
class Article(models.Model):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Liste des articles en vente : prix, nom, et attribut iscotisation
|
|
|
|
et duree si c'est une cotisation"""
|
2016-11-01 01:14:06 +00:00
|
|
|
PRETTY_NAME = "Articles en vente"
|
|
|
|
|
2017-10-28 02:59:40 +00:00
|
|
|
USER_TYPES = (
|
|
|
|
('Adherent', 'Adherent'),
|
|
|
|
('Club', 'Club'),
|
|
|
|
('All', 'All'),
|
|
|
|
)
|
|
|
|
|
|
|
|
COTISATION_TYPE = (
|
|
|
|
('Connexion', 'Connexion'),
|
|
|
|
('Adhesion', 'Adhesion'),
|
|
|
|
('All', 'All'),
|
|
|
|
)
|
|
|
|
|
2017-10-29 10:57:18 +00:00
|
|
|
name = models.CharField(max_length=255)
|
2016-07-02 13:58:50 +00:00
|
|
|
prix = models.DecimalField(max_digits=5, decimal_places=2)
|
2017-10-15 18:37:21 +00:00
|
|
|
duration = models.PositiveIntegerField(
|
2017-07-18 21:57:57 +00:00
|
|
|
help_text="Durée exprimée en mois entiers",
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
2017-07-22 15:57:58 +00:00
|
|
|
validators=[MinValueValidator(0)])
|
2017-10-28 02:59:40 +00:00
|
|
|
type_user = models.CharField(
|
|
|
|
choices=USER_TYPES,
|
|
|
|
default='All',
|
|
|
|
max_length=255
|
|
|
|
)
|
|
|
|
type_cotisation = models.CharField(
|
|
|
|
choices=COTISATION_TYPE,
|
|
|
|
default=None,
|
|
|
|
blank=True,
|
|
|
|
null=True,
|
|
|
|
max_length=255
|
|
|
|
)
|
2017-06-26 17:23:01 +00:00
|
|
|
|
2017-10-29 10:57:18 +00:00
|
|
|
unique_together = ('name', 'type_user')
|
|
|
|
|
2017-06-26 17:23:01 +00:00
|
|
|
def clean(self):
|
|
|
|
if self.name.lower() == "solde":
|
|
|
|
raise ValidationError("Solde est un nom d'article invalide")
|
2017-10-28 02:59:40 +00:00
|
|
|
if self.type_cotisation and not self.duration:
|
|
|
|
raise ValidationError(
|
|
|
|
"La durée est obligatoire si il s'agit d'une cotisation"
|
|
|
|
)
|
2017-06-26 17:23:01 +00:00
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def get_instance(articleid, *args, **kwargs):
|
|
|
|
return Article.objects.get(pk=articleid)
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'ajouter des articles"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_edit_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'éditer des articles"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'éditer des articles"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_delete_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit de supprimer des articles"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit de supprimer des articles"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit de voir des articles"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit de voir des articles"
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
class Banque(models.Model):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Liste des banques"""
|
2016-11-01 01:14:06 +00:00
|
|
|
PRETTY_NAME = "Banques enregistrées"
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
name = models.CharField(max_length=255)
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def get_instance(banqueid, *args, **kwargs):
|
|
|
|
return Banque.objects.get(pk=banqueid)
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit d'ajouter des banques"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_edit_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'éditer des banques"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'éditer des banques"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_delete_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit de supprimer des banques"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit de supprimer des banques"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit de voir des banques"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit de voir des banques"
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
class Paiement(models.Model):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Moyens de paiement"""
|
2016-11-01 01:14:06 +00:00
|
|
|
PRETTY_NAME = "Moyens de paiement"
|
2017-07-18 21:57:57 +00:00
|
|
|
PAYMENT_TYPES = (
|
2017-08-18 22:58:42 +00:00
|
|
|
(0, 'Autre'),
|
|
|
|
(1, 'Chèque'),
|
2017-07-18 21:57:57 +00:00
|
|
|
)
|
2016-11-01 01:14:06 +00:00
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
moyen = models.CharField(max_length=255)
|
2017-09-02 11:03:37 +00:00
|
|
|
type_paiement = models.IntegerField(choices=PAYMENT_TYPES, default=0)
|
2016-07-02 13:58:50 +00:00
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def get_instance(paiementid, *args, **kwargs):
|
|
|
|
return Paiement.objects.get(pk=paiementid)
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'ajouter des paiements"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_edit_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'éditer des paiements"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit d'éditer des paiements"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_delete_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit de supprimer des paiements"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('tresorier',)), u"Vous n'avez pas le\
|
|
|
|
droit de supprimer des paiements"
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit de voir des paiements"
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
|
|
|
return user_request.has_perms(('cableur',)), u"Vous n'avez pas le\
|
|
|
|
droit de voir des paiements"
|
|
|
|
|
2016-07-02 13:58:50 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.moyen
|
|
|
|
|
2017-06-26 17:23:01 +00:00
|
|
|
def clean(self):
|
|
|
|
self.moyen = self.moyen.title()
|
|
|
|
|
2017-09-04 13:31:48 +00:00
|
|
|
def save(self, *args, **kwargs):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Un seul type de paiement peut-etre cheque..."""
|
2017-09-04 13:31:48 +00:00
|
|
|
if Paiement.objects.filter(type_paiement=1).count() > 1:
|
2017-10-13 02:07:56 +00:00
|
|
|
raise ValidationError("On ne peut avoir plusieurs mode de paiement\
|
|
|
|
chèque")
|
2017-09-04 13:31:48 +00:00
|
|
|
super(Paiement, self).save(*args, **kwargs)
|
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2016-07-02 16:30:59 +00:00
|
|
|
class Cotisation(models.Model):
|
2017-10-13 02:07:56 +00:00
|
|
|
"""Objet cotisation, debut et fin, relié en onetoone à une vente"""
|
2016-11-01 01:14:06 +00:00
|
|
|
PRETTY_NAME = "Cotisations"
|
|
|
|
|
2017-10-28 02:59:40 +00:00
|
|
|
COTISATION_TYPE = (
|
|
|
|
('Connexion', 'Connexion'),
|
|
|
|
('Adhesion', 'Adhesion'),
|
|
|
|
('All', 'All'),
|
|
|
|
)
|
|
|
|
|
2016-07-17 18:08:56 +00:00
|
|
|
vente = models.OneToOneField('Vente', on_delete=models.CASCADE, null=True)
|
2017-10-28 02:59:40 +00:00
|
|
|
type_cotisation = models.CharField(
|
|
|
|
choices=COTISATION_TYPE,
|
|
|
|
max_length=255,
|
|
|
|
)
|
2016-07-02 19:17:21 +00:00
|
|
|
date_start = models.DateTimeField()
|
2016-07-02 16:30:59 +00:00
|
|
|
date_end = models.DateTimeField()
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def get_instance(cotisationid, *args, **kwargs):
|
|
|
|
return Cotisations.objects.get(pk=cotisationid)
|
|
|
|
|
|
|
|
def can_create(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_edit_all(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_edit(self, user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_delete_all(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_delete(self, user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-11 21:02:32 +00:00
|
|
|
def can_view_all(user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2017-12-08 22:59:20 +00:00
|
|
|
def can_view(self, user_request, *args, **kwargs):
|
|
|
|
return True, None
|
|
|
|
|
2016-07-02 16:30:59 +00:00
|
|
|
def __str__(self):
|
2016-07-17 18:08:56 +00:00
|
|
|
return str(self.vente)
|
2016-07-02 16:30:59 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2017-09-01 01:15:54 +00:00
|
|
|
@receiver(post_save, sender=Cotisation)
|
|
|
|
def cotisation_post_save(sender, **kwargs):
|
2017-10-13 21:15:07 +00:00
|
|
|
"""Après modification d'une cotisation, regeneration des services"""
|
2017-09-01 01:15:54 +00:00
|
|
|
regen('dns')
|
|
|
|
regen('dhcp')
|
|
|
|
regen('mac_ip_list')
|
2017-09-14 18:03:28 +00:00
|
|
|
regen('mailing')
|
2017-09-01 01:15:54 +00:00
|
|
|
|
2017-10-13 02:07:56 +00:00
|
|
|
|
2017-09-01 01:15:54 +00:00
|
|
|
@receiver(post_delete, sender=Cotisation)
|
|
|
|
def vente_post_delete(sender, **kwargs):
|
2017-10-13 21:15:07 +00:00
|
|
|
"""Après suppression d'une vente, régénération des services"""
|
2017-09-01 01:15:54 +00:00
|
|
|
cotisation = kwargs['instance']
|
2017-09-01 20:21:51 +00:00
|
|
|
regen('mac_ip_list')
|
2017-09-14 18:03:28 +00:00
|
|
|
regen('mailing')
|