models.py 4.0 KB

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