8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-22 23:13:46 +00:00

Add the need_membership field to article

This field is a boolean indicating if the article can be purshased by
nonmembers.
This commit is contained in:
histausse 2020-09-25 19:11:19 +02:00 committed by Gabriel Detraz
parent 640499a9e2
commit a01c9e2303
3 changed files with 57 additions and 3 deletions

View file

@ -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'),
),
]

View file

@ -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),
]

View file

@ -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