mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 16:33:47 +00:00
Pylint et docstring des fichiers
This commit is contained in:
parent
a3cc5d15c7
commit
81ed00ab5f
3 changed files with 78 additions and 28 deletions
|
@ -30,26 +30,33 @@ from .models import Facture, Article, Banque, Paiement, Cotisation, Vente
|
||||||
|
|
||||||
|
|
||||||
class FactureAdmin(VersionAdmin):
|
class FactureAdmin(VersionAdmin):
|
||||||
|
"""Class admin d'une facture, tous les champs"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class VenteAdmin(VersionAdmin):
|
class VenteAdmin(VersionAdmin):
|
||||||
|
"""Class admin d'une vente, tous les champs (facture related)"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ArticleAdmin(VersionAdmin):
|
class ArticleAdmin(VersionAdmin):
|
||||||
|
"""Class admin d'un article en vente"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class BanqueAdmin(VersionAdmin):
|
class BanqueAdmin(VersionAdmin):
|
||||||
|
"""Class admin de la liste des banques (facture related)"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class PaiementAdmin(VersionAdmin):
|
class PaiementAdmin(VersionAdmin):
|
||||||
|
"""Class admin d'un moyen de paiement (facture related"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class CotisationAdmin(VersionAdmin):
|
class CotisationAdmin(VersionAdmin):
|
||||||
|
"""Class admin d'une cotisation (date de debut et de fin),
|
||||||
|
Vente related"""
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,28 @@
|
||||||
# You should have received a copy of the GNU General Public License along
|
# 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.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""
|
||||||
|
Forms de l'application cotisation de re2o. Dépendance avec les models,
|
||||||
|
importé par les views.
|
||||||
|
|
||||||
|
Permet de créer une nouvelle facture pour un user (NewFactureForm),
|
||||||
|
et de l'editer (soit l'user avec EditFactureForm,
|
||||||
|
soit le trésorier avec TrezEdit qui a plus de possibilités que self
|
||||||
|
notamment sur le controle trésorier)
|
||||||
|
|
||||||
|
SelectArticleForm est utilisée lors de la creation d'une facture en
|
||||||
|
parrallèle de NewFacture pour le choix des articles désirés.
|
||||||
|
(la vue correspondante est unique)
|
||||||
|
|
||||||
|
ArticleForm, BanqueForm, PaiementForm permettent aux admin d'ajouter,
|
||||||
|
éditer ou supprimer une banque/moyen de paiement ou un article
|
||||||
|
"""
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import forms
|
from django import forms
|
||||||
from django.forms import ModelForm, Form
|
from django.forms import ModelForm, Form
|
||||||
from django import forms
|
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
from .models import Article, Paiement, Facture, Banque, Vente
|
from .models import Article, Paiement, Facture, Banque
|
||||||
|
|
||||||
|
|
||||||
class NewFactureForm(ModelForm):
|
class NewFactureForm(ModelForm):
|
||||||
|
|
|
@ -20,20 +20,39 @@
|
||||||
# You should have received a copy of the GNU General Public License along
|
# 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.,
|
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
from django.db.models.signals import post_save, post_delete
|
from django.db.models.signals import post_save, post_delete
|
||||||
from django.dispatch import receiver
|
from django.dispatch import receiver
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from django.forms import ValidationError
|
from django.forms import ValidationError
|
||||||
from django.core.validators import MinValueValidator
|
from django.core.validators import MinValueValidator
|
||||||
|
|
||||||
from django.db.models import Max
|
from django.db.models import Max
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from machines.models import regen
|
from machines.models import regen
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,6 +76,8 @@ class Facture(models.Model):
|
||||||
control = models.BooleanField(default=False)
|
control = models.BooleanField(default=False)
|
||||||
|
|
||||||
def prix(self):
|
def prix(self):
|
||||||
|
"""Renvoie le prix brut sans les quantités. Méthode
|
||||||
|
dépréciée"""
|
||||||
prix = Vente.objects.filter(
|
prix = Vente.objects.filter(
|
||||||
facture=self
|
facture=self
|
||||||
).aggregate(models.Sum('prix'))['prix__sum']
|
).aggregate(models.Sum('prix'))['prix__sum']
|
||||||
|
@ -95,6 +116,7 @@ def facture_post_save(sender, **kwargs):
|
||||||
|
|
||||||
@receiver(post_delete, sender=Facture)
|
@receiver(post_delete, sender=Facture)
|
||||||
def facture_post_delete(sender, **kwargs):
|
def facture_post_delete(sender, **kwargs):
|
||||||
|
"""Après la suppression d'une facture, on synchronise l'user ldap"""
|
||||||
user = kwargs['instance'].user
|
user = kwargs['instance'].user
|
||||||
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
user.ldap_sync(base=False, access_refresh=True, mac_refresh=False)
|
||||||
|
|
||||||
|
@ -120,6 +142,9 @@ class Vente(models.Model):
|
||||||
return self.prix*self.number
|
return self.prix*self.number
|
||||||
|
|
||||||
def update_cotisation(self):
|
def update_cotisation(self):
|
||||||
|
"""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"""
|
||||||
if hasattr(self, 'cotisation'):
|
if hasattr(self, 'cotisation'):
|
||||||
cotisation = self.cotisation
|
cotisation = self.cotisation
|
||||||
cotisation.date_end = cotisation.date_start + relativedelta(
|
cotisation.date_end = cotisation.date_start + relativedelta(
|
||||||
|
@ -181,6 +206,8 @@ def vente_post_save(sender, **kwargs):
|
||||||
|
|
||||||
@receiver(post_delete, sender=Vente)
|
@receiver(post_delete, sender=Vente)
|
||||||
def vente_post_delete(sender, **kwargs):
|
def vente_post_delete(sender, **kwargs):
|
||||||
|
"""Après suppression d'une vente, on synchronise l'user ldap (ex
|
||||||
|
suppression d'une cotisation"""
|
||||||
vente = kwargs['instance']
|
vente = kwargs['instance']
|
||||||
if vente.iscotisation:
|
if vente.iscotisation:
|
||||||
user = vente.facture.user
|
user = vente.facture.user
|
||||||
|
@ -258,6 +285,7 @@ class Cotisation(models.Model):
|
||||||
|
|
||||||
@receiver(post_save, sender=Cotisation)
|
@receiver(post_save, sender=Cotisation)
|
||||||
def cotisation_post_save(sender, **kwargs):
|
def cotisation_post_save(sender, **kwargs):
|
||||||
|
"""Après modification d'une cotisation, regeneration des services"""
|
||||||
regen('dns')
|
regen('dns')
|
||||||
regen('dhcp')
|
regen('dhcp')
|
||||||
regen('mac_ip_list')
|
regen('mac_ip_list')
|
||||||
|
@ -266,6 +294,7 @@ def cotisation_post_save(sender, **kwargs):
|
||||||
|
|
||||||
@receiver(post_delete, sender=Cotisation)
|
@receiver(post_delete, sender=Cotisation)
|
||||||
def vente_post_delete(sender, **kwargs):
|
def vente_post_delete(sender, **kwargs):
|
||||||
|
"""Après suppression d'une vente, régénération des services"""
|
||||||
cotisation = kwargs['instance']
|
cotisation = kwargs['instance']
|
||||||
regen('mac_ip_list')
|
regen('mac_ip_list')
|
||||||
regen('mailing')
|
regen('mailing')
|
||||||
|
|
Loading…
Reference in a new issue