From f2bdc766d92449457f776bb24ea84ae569622bd2 Mon Sep 17 00:00:00 2001 From: histausse Date: Fri, 25 Sep 2020 19:11:19 +0200 Subject: [PATCH] Add the need_membership field to article This field is a boolean indicating if the article can be purshased by nonmembers. --- .../0046_article_need_membership.py | 20 +++++++++++++ .../0047_article_need_membership_init.py | 28 +++++++++++++++++++ cotisations/models.py | 10 +++++-- 3 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 cotisations/migrations/0046_article_need_membership.py create mode 100644 cotisations/migrations/0047_article_need_membership_init.py 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 efe3008e..aa293e4a 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", @@ -787,9 +793,7 @@ class Article(RevMixin, AclMixin, models.Model): objects_pool = objects_pool.filter( Q(duration_membership__gt=0) |Q(duration_days_membership__gt=0) - |~(Q(duration_connection__gt=0) # BAD nonstandard hardcoded comportmant - |Q(duration_days_connection__gt=0) - ) + |Q(need_membership=False) ) if user.has_perm("cotisations.buy_every_article"): return objects_pool