From 23698a1653672ac3ccd35726f2a8a05f1b583ceb Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Thu, 15 Oct 2020 19:21:16 +0200 Subject: [PATCH] Fix the test for ventes in the set_active function. This function could be greatly improved if the duraction could not be null. --- users/models.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/users/models.py b/users/models.py index f35149dc..0253cb97 100755 --- a/users/models.py +++ b/users/models.py @@ -931,10 +931,14 @@ class User( """ if self.state == self.STATE_NOT_YET_ACTIVE: - if self.facture_set.filter(valid=True).filter( - ~(Q(vente__duration_membership__isnull=True) | Q(vente__duration_membership=0)))\ - .filter(~(Q(vente__duration_days_membership__isnull=True) | Q(vente__duration_days_membership=0)) - ).exists() or OptionalUser.get_cached_value("all_users_active"): + # Look for ventes with non 0 and non null subscription duration in the invoices set + not_null = self.facture_set.filter(valid=True).exclude(Q(vente__duration_membership__isnull=True)).exists() + not_zero = self.facture_set.filter(valid=True).exclude(Q(vente__duration_membership=0)).exists() + days_not_null = self.facture_set.filter(valid=True).exclude(Q(vente__duration_days_membership__isnull=True)).exists() + days_not_zero = self.facture_set.filter(valid=True).exclude(Q(vente__duration_days_membership=0)).exists() + # if any vente is found, activate the user + if(not_null or not_zero or days_not_null or days_not_zero \ + or OptionalUser.get_cached_value("all_users_active")): self.state = self.STATE_ACTIVE self.save() if self.state == self.STATE_ARCHIVE or self.state == self.STATE_FULL_ARCHIVE: