models.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. # -*- coding: utf-8 -*-
  2. import datetime
  3. from django.db import models
  4. class Offer(models.Model):
  5. """Description of an offer available to subscribers.
  6. Implementation notes:
  7. configuration_type store the model name of the configuration backend
  8. (ex VPNConfiguration).
  9. The choices list is dynamically generated at start in the __init__
  10. """
  11. def __init__(self, *args, **kwargs):
  12. from coin.configuration.models import Configuration
  13. super(Offer, self).__init__(*args, **kwargs)
  14. """
  15. Génère automatiquement la liste de choix possibles de types
  16. de configurations en fonction des classes enfants de Configuration
  17. """
  18. self._meta.get_field_by_name('configuration_type')[0]._choices = (
  19. Configuration.get_configurations_choices_list())
  20. name = models.CharField(max_length=255, blank=False, null=False,
  21. verbose_name='Nom de l\'offre')
  22. configuration_type = models.CharField(max_length=50,
  23. null=True,
  24. choices = (('',''),),
  25. help_text="Type of configuration to use with this offer")
  26. billing_period = models.IntegerField(blank=False, null=False, default=1,
  27. verbose_name='Période de facturation',
  28. help_text='en mois')
  29. period_fees = models.DecimalField(max_digits=5, decimal_places=2,
  30. blank=False, null=False,
  31. verbose_name='Montant par période de '
  32. 'facturation',
  33. help_text='en €')
  34. initial_fees = models.DecimalField(max_digits=5, decimal_places=2,
  35. blank=False, null=False,
  36. verbose_name='Frais de mise en service',
  37. help_text='en €')
  38. def get_configuration_type_display(self):
  39. """
  40. Renvoi le nom affichable du type de configuration
  41. """
  42. for item in Configuration.get_configurations_choices_list():
  43. if item and self.configuration_type in item:
  44. return item[1]
  45. return self.configuration_type
  46. def __unicode__(self):
  47. return u'%s : %s - %d€ / %im' % (
  48. self.get_configuration_type_display(),
  49. self.name,
  50. self.period_fees,
  51. self.billing_period)
  52. class Meta:
  53. verbose_name = 'offre'
  54. class OfferSubscription(models.Model):
  55. """Only contains administrative details about a subscription, not
  56. technical. Nothing here should end up into the LDAP backend.
  57. Implementation notes: the Configuration model (which actually implementing the backend
  58. (technical configuration for the technology)) relate to this class
  59. with a OneToOneField
  60. """
  61. subscription_date = models.DateField(
  62. null=False,
  63. blank=False,
  64. default=datetime.date.today,
  65. verbose_name='Date de souscription à l\'offre')
  66. # TODO: for data retention, prevent deletion of a subscription object
  67. # while the resign date is recent enough (e.g. one year in France).
  68. resign_date = models.DateField(
  69. null=True,
  70. blank=True,
  71. verbose_name='Date de résiliation')
  72. # TODO: move this to offers?
  73. commitment = models.IntegerField(blank=False, null=False,
  74. verbose_name='Période d\'engagement',
  75. help_text = 'en mois',
  76. default=0)
  77. member = models.ForeignKey('members.Member', verbose_name='Membre')
  78. offer = models.ForeignKey('Offer', verbose_name='Offre')
  79. def __unicode__(self):
  80. return u'%s - %s - %s' % (self.member, self.offer.name,
  81. self.subscription_date)
  82. class Meta:
  83. verbose_name = 'abonnement'