From c76f32cf260cd6fd379d24c3aa3e5163c9c9204c Mon Sep 17 00:00:00 2001 From: Hugo Levy-Falk Date: Wed, 2 Oct 2019 23:42:54 +0200 Subject: [PATCH] Fix #222 --- .../migrations/0040_auto_20191002_2335.py | 26 +++++++++++++++++++ cotisations/models.py | 23 +++++++++++++--- .../templates/cotisations/aff_article.html | 2 ++ cotisations/views.py | 1 + 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 cotisations/migrations/0040_auto_20191002_2335.py diff --git a/cotisations/migrations/0040_auto_20191002_2335.py b/cotisations/migrations/0040_auto_20191002_2335.py new file mode 100644 index 00000000..56c99f69 --- /dev/null +++ b/cotisations/migrations/0040_auto_20191002_2335.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.23 on 2019-10-02 21:35 +from __future__ import unicode_literals + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cotisations', '0039_freepayment'), + ] + + operations = [ + migrations.AddField( + model_name='article', + name='duration_days', + field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration (in days, will be added to duration in months)'), + ), + migrations.AddField( + model_name='vente', + name='duration_days', + field=models.PositiveIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(0)], verbose_name='duration (in days, will be added to duration in months)'), + ), + ] diff --git a/cotisations/models.py b/cotisations/models.py index 3cb64ec3..b9d01b8d 100644 --- a/cotisations/models.py +++ b/cotisations/models.py @@ -460,6 +460,12 @@ class Vente(RevMixin, AclMixin, models.Model): null=True, verbose_name=_("duration (in months)") ) + duration_days = models.PositiveIntegerField( + blank=True, + null=True, + validators=[MinValueValidator(0)], + verbose_name=_("duration (in days, will be added to duration in months)") + ) # TODO : this field is not needed if you use Article ForeignKey type_cotisation = models.CharField( choices=COTISATION_TYPE, @@ -492,7 +498,9 @@ class Vente(RevMixin, AclMixin, models.Model): if hasattr(self, 'cotisation'): cotisation = self.cotisation cotisation.date_end = cotisation.date_start + relativedelta( - months=self.duration*self.number) + months=(self.duration or 0)*self.number, + days=(self.duration_days or 0)*self.number, + ) return def create_cotis(self, date_start=False): @@ -529,7 +537,8 @@ class Vente(RevMixin, AclMixin, models.Model): date_max = max(end_cotisation, date_start) cotisation.date_start = date_max cotisation.date_end = cotisation.date_start + relativedelta( - months=self.duration*self.number + months=(self.duration or 0)*self.number, + days=(self.duration_days or 0)*self.number, ) return @@ -540,7 +549,7 @@ class Vente(RevMixin, AclMixin, models.Model): effect on the user's cotisation """ # Checking that if a cotisation is specified, there is also a duration - if self.type_cotisation and not self.duration: + if self.type_cotisation and not (self.duration or self.duration_days): raise ValidationError( _("Duration must be specified for a subscription.") ) @@ -695,6 +704,12 @@ class Article(RevMixin, AclMixin, models.Model): validators=[MinValueValidator(0)], verbose_name=_("duration (in months)") ) + duration_days = models.PositiveIntegerField( + blank=True, + null=True, + validators=[MinValueValidator(0)], + verbose_name=_("duration (in days, will be added to duration in months)") + ) type_user = models.CharField( choices=USER_TYPES, default='All', @@ -729,7 +744,7 @@ class Article(RevMixin, AclMixin, models.Model): raise ValidationError( _("Balance is a reserved article name.") ) - if self.type_cotisation and not self.duration: + if self.type_cotisation and not (self.duration or self.duration_days): raise ValidationError( _("Duration must be specified for a subscription.") ) diff --git a/cotisations/templates/cotisations/aff_article.html b/cotisations/templates/cotisations/aff_article.html index df187abb..7ead24dc 100644 --- a/cotisations/templates/cotisations/aff_article.html +++ b/cotisations/templates/cotisations/aff_article.html @@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {% trans "Price" %} {% trans "Subscription type" %} {% trans "Duration (in months)" %} + {% trans "Duration (in days)" %} {% trans "Concerned users" %} {% trans "Available for everyone" %} @@ -45,6 +46,7 @@ with this program; if not, write to the Free Software Foundation, Inc., {{ article.prix }} {{ article.type_cotisation }} {{ article.duration }} + {{ article.duration_days }} {{ article.type_user }} {{ article.available_for_everyone | tick }} diff --git a/cotisations/views.py b/cotisations/views.py index 437d5df1..2a262704 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -139,6 +139,7 @@ def new_facture(request, user, userid): prix=article.prix, type_cotisation=article.type_cotisation, duration=article.duration, + duration_days=article.duration_days, number=quantity ) purchases.append(new_purchase)