From ca0a6298bb7648f9158508f98b30607eb0eae5f3 Mon Sep 17 00:00:00 2001 From: chirac Date: Tue, 26 Jul 2016 00:13:38 +0200 Subject: [PATCH] Maj le dialup quand edition de facture --- cotisations/models.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/cotisations/models.py b/cotisations/models.py index 658f4536..7b729aa7 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -1,5 +1,7 @@ from django.db import models +from django.db.models.signals import post_save, post_delete +from django.dispatch import receiver from dateutil.relativedelta import relativedelta from django.core.validators import MinValueValidator @@ -26,6 +28,17 @@ class Facture(models.Model): def __str__(self): return str(self.date) + ' ' + str(self.user) +@receiver(post_save, sender=Facture) +def facture_post_save(sender, **kwargs): + facture = kwargs['instance'] + user = facture.user + user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + +@receiver(post_delete, sender=Facture) +def facture_post_delete(sender, **kwargs): + user = kwargs['instance'].user + user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + class Vente(models.Model): facture = models.ForeignKey('Facture', on_delete=models.CASCADE) number = models.IntegerField(validators=[MinValueValidator(1)]) @@ -46,6 +59,20 @@ class Vente(models.Model): def __str__(self): return str(self.name) + ' ' + str(self.facture) +@receiver(post_save, sender=Vente) +def vente_post_save(sender, **kwargs): + vente = kwargs['instance'] + if vente.iscotisation: + user = vente.facture.user + user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + +@receiver(post_delete, sender=Vente) +def vente_post_delete(sender, **kwargs): + vente = kwargs['instance'] + if vente.iscotisation: + user = vente.facture.user + user.ldap_sync(base=False, access_refresh=True, mac_refresh=False) + class Article(models.Model): name = models.CharField(max_length=255) prix = models.DecimalField(max_digits=5, decimal_places=2)