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.,