models.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. help_text="Type of configuration to use with this offer")
  27. billing_period = models.IntegerField(blank=False, null=False, default=1,
  28. verbose_name='période de facturation',
  29. help_text='en mois')
  30. period_fees = models.DecimalField(max_digits=5, decimal_places=2,
  31. blank=False, null=False,
  32. verbose_name='montant par période de '
  33. 'facturation',
  34. help_text='en €')
  35. initial_fees = models.DecimalField(max_digits=5, decimal_places=2,
  36. blank=False, null=False,
  37. verbose_name='frais de mise en service',
  38. help_text='en €')
  39. def get_configuration_type_display(self):
  40. """
  41. Renvoi le nom affichable du type de configuration
  42. """
  43. for item in Configuration.get_configurations_choices_list():
  44. if item and self.configuration_type in item:
  45. return item[1]
  46. return self.configuration_type
  47. def __unicode__(self):
  48. return '%s : %s - %d€ / %im' % (
  49. self.get_configuration_type_display(),
  50. self.name,
  51. self.period_fees,
  52. self.billing_period)
  53. class Meta:
  54. verbose_name = 'offre'
  55. class OfferSubscription(models.Model):
  56. """Only contains administrative details about a subscription, not
  57. technical. Nothing here should end up into the LDAP backend.
  58. Implementation notes: the Configuration model (which actually implementing the backend
  59. (technical configuration for the technology)) relate to this class
  60. with a OneToOneField
  61. """
  62. subscription_date = models.DateField(
  63. null=False,
  64. blank=False,
  65. default=datetime.date.today,
  66. verbose_name="date de souscription à l'offre")
  67. # TODO: for data retention, prevent deletion of a subscription object
  68. # while the resign date is recent enough (e.g. one year in France).
  69. resign_date = models.DateField(
  70. null=True,
  71. blank=True,
  72. verbose_name='date de résiliation')
  73. # TODO: move this to offers?
  74. commitment = models.IntegerField(blank=False, null=False,
  75. verbose_name="période d'engagement",
  76. help_text = 'en mois',
  77. default=0)
  78. member = models.ForeignKey('members.Member', verbose_name='membre')
  79. offer = models.ForeignKey('Offer', verbose_name='offre')
  80. def __unicode__(self):
  81. return '%s - %s - %s' % (self.member, self.offer.name,
  82. self.subscription_date)
  83. class Meta:
  84. verbose_name = 'abonnement'