Browse Source

Ensure that billing period and commitment are positive

Baptiste Jonglez 10 years ago
parent
commit
b622e5e973
2 changed files with 32 additions and 2 deletions
  1. 27 0
      coin/offers/migrations/0005_auto_20150210_0923.py
  2. 5 2
      coin/offers/models.py

+ 27 - 0
coin/offers/migrations/0005_auto_20150210_0923.py

@@ -0,0 +1,27 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+import django.core.validators
+
+
+class Migration(migrations.Migration):
+
+    dependencies = [
+        ('offers', '0004_auto_20150120_2309'),
+    ]
+
+    operations = [
+        migrations.AlterField(
+            model_name='offer',
+            name='billing_period',
+            field=models.IntegerField(default=1, help_text='en mois', verbose_name='p\xe9riode de facturation', validators=[django.core.validators.MinValueValidator(1)]),
+            preserve_default=True,
+        ),
+        migrations.AlterField(
+            model_name='offersubscription',
+            name='commitment',
+            field=models.IntegerField(default=0, help_text='en mois', verbose_name="p\xe9riode d'engagement", validators=[django.core.validators.MinValueValidator(0)]),
+            preserve_default=True,
+        ),
+    ]

+ 5 - 2
coin/offers/models.py

@@ -5,6 +5,7 @@ import datetime
 
 from django.db import models
 from django.db.models import Q
+from django.core.validators import MinValueValidator
 
 
 class Offer(models.Model):
@@ -24,7 +25,8 @@ class Offer(models.Model):
                             help_text="Type de configuration à utiliser avec cette offre")
     billing_period = models.IntegerField(blank=False, null=False, default=1,
                                          verbose_name='période de facturation',
-                                         help_text='en mois')
+                                         help_text='en mois',
+                                         validators=[MinValueValidator(1)])
     period_fees = models.DecimalField(max_digits=5, decimal_places=2,
                                       blank=False, null=False,
                                       verbose_name='montant par période de '
@@ -95,7 +97,8 @@ class OfferSubscription(models.Model):
     # TODO: move this to offers?
     commitment = models.IntegerField(blank=False, null=False,
                                      verbose_name="période d'engagement",
-                                     help_text = 'en mois',
+                                     help_text='en mois',
+                                     validators=[MinValueValidator(0)],
                                      default=0)
     member = models.ForeignKey('members.Member', verbose_name='membre')
     offer = models.ForeignKey('Offer', verbose_name='offre')