From 7ac894c168cadbc363a395e580d54174de1e86fe Mon Sep 17 00:00:00 2001 From: grisel-davy Date: Sat, 17 Oct 2020 00:34:56 +0200 Subject: [PATCH] Replace null by 0 in default value of duration_* --- .../migrations/0048_auto_20201017_0018.py | 50 +++++++++++++++++++ cotisations/models.py | 14 +++--- users/models.py | 11 ++-- 3 files changed, 60 insertions(+), 15 deletions(-) create mode 100644 cotisations/migrations/0048_auto_20201017_0018.py diff --git a/cotisations/migrations/0048_auto_20201017_0018.py b/cotisations/migrations/0048_auto_20201017_0018.py new file mode 100644 index 00000000..88897b79 --- /dev/null +++ b/cotisations/migrations/0048_auto_20201017_0018.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-10-16 22:18 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0047_article_need_membership_init'), + ] + + +def set_value_to_0(apps, schema_editor): + ventes = apps.get_model("cotisations", "Vente") + ventes.filter(duration_connection__isnull=True).update(duration_connection=0) + ventes.filter(duration_days_connection__isnull=True).update(duration_days_connection=0) + ventes.filter(duration_membership__isnull=True).update(duration_membership=0) + ventes.filter(duration_days_membership__isnull=True).update(duration_days_membership=0) + + operations = [ + migrations.RunPython(set_value_to_0), + migrations.AlterField( + model_name='article', + name='need_membership', + field=models.BooleanField(default=True, verbose_name='need membership to be purchased'), + ), + migrations.AlterField( + model_name='vente', + name='duration_connection', + field=models.PositiveIntegerField(default=0, verbose_name='duration of the connection (in months)'), + ), + migrations.AlterField( + model_name='vente', + name='duration_days_connection', + field=models.PositiveIntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the connection (in days, will be added to duration in months)'), + ), + migrations.AlterField( + model_name='vente', + name='duration_days_membership', + field=models.PositiveIntegerField(default=0, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration of the membership (in days, will be added to duration in months)'), + ), + migrations.AlterField( + model_name='vente', + name='duration_membership', + field=models.PositiveIntegerField(default=0, verbose_name='duration of the membership (in months)'), + ), + ] diff --git a/cotisations/models.py b/cotisations/models.py index 30256397..2e71d418 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -283,8 +283,8 @@ class Facture(BaseInvoice): """Returns every subscription associated with this invoice.""" return Cotisation.objects.filter( vente__in=self.vente_set.filter( - ~(Q(duration_membership__isnull=True) | Q(duration_membership=0)) |\ - ~(Q(duration_days_membership__isnull=True) | Q(duration_days_membership=0)) + ~(Q(duration_membership=0)) |\ + ~(Q(duration_days_membership=0)) ) ) @@ -453,20 +453,18 @@ class Vente(RevMixin, AclMixin, models.Model): prix = models.DecimalField(max_digits=5, decimal_places=2, verbose_name=_("price")) # TODO : this field is not needed if you use Article ForeignKey duration_connection = models.PositiveIntegerField( - blank=True, null=True, verbose_name=_("duration of the connection (in months)") + default=0, verbose_name=_("duration of the connection (in months)") ) duration_days_connection = models.PositiveIntegerField( - blank=True, - null=True, + default=0, validators=[MinValueValidator(0)], verbose_name=_("duration of the connection (in days, will be added to duration in months)"), ) duration_membership = models.PositiveIntegerField( - blank=True, null=True, verbose_name=_("duration of the membership (in months)") + default=0, verbose_name=_("duration of the membership (in months)") ) duration_days_membership = models.PositiveIntegerField( - blank=True, - null=True, + default=0, validators=[MinValueValidator(0)], verbose_name=_("duration of the membership (in days, will be added to duration in months)"), ) diff --git a/users/models.py b/users/models.py index 0253cb97..f3a67917 100755 --- a/users/models.py +++ b/users/models.py @@ -931,16 +931,13 @@ class User( """ if self.state == self.STATE_NOT_YET_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() + # Look for ventes with non 0 subscription duration in the invoices set 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 \ + if(not_zero or days_not_zero\ or OptionalUser.get_cached_value("all_users_active")): - self.state = self.STATE_ACTIVE - self.save() + self.state = self.STATE_ACTIVE + self.save() if self.state == self.STATE_ARCHIVE or self.state == self.STATE_FULL_ARCHIVE: self.state = self.STATE_ACTIVE self.unarchive()