|
@@ -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 '
|
|
@@ -49,11 +51,25 @@ class Offer(models.Model):
|
|
|
return self.configuration_type
|
|
|
get_configuration_type_display.short_description = 'type de configuration'
|
|
|
|
|
|
+ def display_price(self):
|
|
|
+ """Displays the price of an offer in a human-readable manner
|
|
|
+ (for instance "30€ / month")
|
|
|
+ """
|
|
|
+ if int(self.period_fees) == self.period_fees:
|
|
|
+ fee = int(self.period_fees)
|
|
|
+ else:
|
|
|
+ fee = self.period_fees
|
|
|
+ if self.billing_period == 1:
|
|
|
+ period = ""
|
|
|
+ else:
|
|
|
+ period = self.billing_period
|
|
|
+ return "{period_fee}€ / {billing_period} mois".format(
|
|
|
+ period_fee=fee,
|
|
|
+ billing_period=period)
|
|
|
+
|
|
|
def __unicode__(self):
|
|
|
- return '{name} - {period_fee}€ / {billing_period}m'.format(
|
|
|
- name=self.name,
|
|
|
- period_fee=self.period_fees,
|
|
|
- billing_period=self.billing_period)
|
|
|
+ return '{name} - {price}'.format(name=self.name,
|
|
|
+ price=self.display_price())
|
|
|
|
|
|
class Meta:
|
|
|
verbose_name = 'offre'
|
|
@@ -81,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')
|