diff --git a/cotisations/migrations/0046_article_need_membership.py b/cotisations/migrations/0046_article_need_membership.py new file mode 100644 index 00000000..08fc6485 --- /dev/null +++ b/cotisations/migrations/0046_article_need_membership.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-09-25 16:45 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0045_separation_membership_connection_p3'), + ] + + operations = [ + migrations.AddField( + model_name='article', + name='need_membership', + field=models.BooleanField(default=True, verbose_name='can be purcharsed without membership'), + ), + ] diff --git a/cotisations/migrations/0047_article_need_membership_init.py b/cotisations/migrations/0047_article_need_membership_init.py new file mode 100644 index 00000000..b268a10a --- /dev/null +++ b/cotisations/migrations/0047_article_need_membership_init.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.29 on 2020-09-25 16:45 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0046_article_need_membership'), + ] + + def init_need_membership(apps, schema_editor): + db_alias = schema_editor.connection.alias + article = apps.get_model("cotisations", "Article") + articles = article.objects.using(db_alias).all() + for art in articles: + v = False + v = v or bool(art.duration_membership) + v = v or bool(art.duration_days_membership) + v = v or not (bool(art.duration_connection) or bool(art.duration_days_connection)) + art.need_membership = v + art.save() + + operations = [ + migrations.RunPython(init_need_membership, lambda *args, **kargs: None), + ] diff --git a/cotisations/models.py b/cotisations/models.py index b5a698cd..c8a0070e 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -678,6 +678,7 @@ class Article(RevMixin, AclMixin, models.Model): * a price * a duration for the membership * a duration for the connection + * if the article can be purchased without membership * a type of user (indicating what kind of user can buy this article) """ @@ -718,6 +719,11 @@ class Article(RevMixin, AclMixin, models.Model): verbose_name=_("duration of the connection (in days, will be added to duration in months)"), ) + need_membership = models.BooleanField( + default=True, + verbose_name=_("need membership to be purchased"), + ) + type_user = models.CharField( choices=USER_TYPES, default="All", @@ -785,9 +791,9 @@ class Article(RevMixin, AclMixin, models.Model): ) if target_user is not None and not target_user.is_adherent(): objects_pool = objects_pool.filter( - Q(type_cotisation="All") - | Q(type_cotisation="Adhesion") - | Q(type_cotisation__isnull=True) + Q(duration_membership__gt=0) + |Q(duration_days_membership__gt=0) + |Q(need_membership=False) ) if user.has_perm("cotisations.buy_every_article"): return objects_pool