1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- # -*- coding: utf-8 -*-
- import datetime
- from django.db import models
- class Offer(models.Model):
- """Description of an offer available to subscribers.
- Implementation notes:
- configuration_type store the model name of the configuration backend
- (ex VPNConfiguration).
- The choices list is dynamically generated at start in the __init__
- """
- def __init__(self, *args, **kwargs):
- from coin.configuration.models import Configuration
- super(Offer, self).__init__(*args, **kwargs)
- """
- Génère automatiquement la liste de choix possibles de types
- de configurations en fonction des classes enfants de Configuration
- """
- self._meta.get_field_by_name('configuration_type')[0]._choices = (
- Configuration.get_configurations_choices_list())
- name = models.CharField(max_length=255, blank=False, null=False,
- verbose_name='Nom de l\'offre')
- configuration_type = models.CharField(max_length=50,
- null=True,
- choices = (('',''),),
- help_text="Type of configuration to use with this offer")
- billing_period = models.IntegerField(blank=False, null=False, default=1,
- verbose_name='Période de facturation',
- help_text='en mois')
- period_fees = models.DecimalField(max_digits=5, decimal_places=2,
- blank=False, null=False,
- verbose_name='Montant par période de '
- 'facturation',
- help_text='en €')
- initial_fees = models.DecimalField(max_digits=5, decimal_places=2,
- blank=False, null=False,
- verbose_name='Frais de mise en service',
- help_text='en €')
- def get_configuration_type_display(self):
- """
- Renvoi le nom affichable du type de configuration
- """
- for item in Configuration.get_configurations_choices_list():
- if item and self.configuration_type in item:
- return item[1]
- return self.configuration_type
- def __unicode__(self):
- return u'%s : %s - %d€ / %im' % (
- self.get_configuration_type_display(),
- self.name,
- self.period_fees,
- self.billing_period)
- class Meta:
- verbose_name = 'offre'
- class OfferSubscription(models.Model):
- """Only contains administrative details about a subscription, not
- technical. Nothing here should end up into the LDAP backend.
- Implementation notes: the Configuration model (which actually implementing the backend
- (technical configuration for the technology)) relate to this class
- with a OneToOneField
- """
- subscription_date = models.DateField(
- null=False,
- blank=False,
- default=datetime.date.today,
- verbose_name='Date de souscription à l\'offre')
- # TODO: for data retention, prevent deletion of a subscription object
- # while the resign date is recent enough (e.g. one year in France).
- resign_date = models.DateField(
- null=True,
- blank=True,
- verbose_name='Date de résiliation')
- # TODO: move this to offers?
- commitment = models.IntegerField(blank=False, null=False,
- verbose_name='Période d\'engagement',
- help_text = 'en mois',
- default=0)
- member = models.ForeignKey('members.Member', verbose_name='Membre')
- offer = models.ForeignKey('Offer', verbose_name='Offre')
- def __unicode__(self):
- return u'%s - %s - %s' % (self.member, self.offer.name,
- self.subscription_date)
- class Meta:
- verbose_name = 'abonnement'
|