Project

General

Profile

Download (21.8 KB) Statistics
| Branch: | Tag: | Revision:

calebasse / calebasse / ressources / models.py @ 9fa48803

1
# -*- coding: utf-8 -*-
2

    
3
from datetime import date, datetime
4
import bisect
5

    
6
from django.db import models
7
from django.db.models import query
8
from model_utils import Choices
9

    
10
from calebasse.models import PhoneNumberField, ZipCodeField
11

    
12
from model_utils.managers import PassThroughManager
13

    
14

    
15
class ServiceLinkedQuerySet(query.QuerySet):
16
    def for_service(self, service, allow_global=True):
17
        '''Allows service local and service global objects'''
18
        return self.filter(models.Q(service=service)
19
                |models.Q(service__isnull=allow_global))
20

    
21
ServiceLinkedManager = PassThroughManager.for_queryset_class(ServiceLinkedQuerySet)
22

    
23
class NamedAbstractModel(models.Model):
24
    name = models.CharField(max_length=150, verbose_name=u'Nom')
25

    
26
    def __unicode__(self):
27
        return self.name
28

    
29
    def __repr__(self):
30
        return '<%s %r>' % (self.__class__.__name__, unicode(self))
31

    
32
    class Meta:
33
        abstract = True
34
        ordering = ['name']
35

    
36
class ServiceLinkedAbstractModel(models.Model):
37
    objects = ServiceLinkedManager()
38
    service = models.ForeignKey('Service', null=True, blank=True)
39

    
40
    class Meta:
41
        abstract = True
42

    
43
DEST_TYPE = {
44
    # code grand regime: type destinataire
45
    '01': 'CT', # regime general
46
    '02': 'MA', # agricole
47
    '03': 'SR', # independant
48
    '04': 'CF', # sncf
49
    '05': 'RP', # ratp
50
    '06': 'EN', # invalide marine
51
    '07': 'RM', # minier
52
    '08': 'CM', # militaire
53
    '10': 'CE', # notaires
54
    '12': 'CI', # cci paris
55
    '14': 'AN', # assemblee nationale
56
    '15': 'SE', # senat
57
    '16': 'PB', # port autonome bordeaux
58
    '90': 'CC', # cultes
59
    '91': 'SM', # ensuite toutes les mutuelles nationales
60
    '92': 'SM',
61
    '93': 'SM',
62
    '94': 'SM',
63
    '95': 'SM',
64
    '96': 'SM',
65
    '99': 'SM',
66
}
67

    
68

    
69
class HealthCenter(NamedAbstractModel):
70
    class Meta:
71
        verbose_name = u'Centre d\'assurance maladie'
72
        verbose_name_plural = u'Centres d\'assurances maladie'
73

    
74
    def __unicode__(self):
75
        return self.large_regime.code + ' ' + self.health_fund + ' ' + self.code + ' ' + self.name
76

    
77
    code = models.CharField(verbose_name=u"Code du centre",
78
            max_length=4,
79
            null=True, blank=True)
80
    large_regime = models.ForeignKey('LargeRegime',
81
            verbose_name=u"Grand régime")
82
    dest_organism = models.CharField(max_length=8,
83
            verbose_name=u"Organisme destinataire")
84
    computer_center_code = models.CharField(max_length=8,
85
            verbose_name=u"Code centre informatique",
86
            null=True, default=True)
87
    abbreviation = models.CharField(verbose_name=u'Abbrévation',
88
            max_length=8,
89
            null=True, default=True)
90
    health_fund = models.CharField(verbose_name=u"Numéro de la caisse",
91
            max_length=3)
92
    active = models.BooleanField(default=True, verbose_name=u"Active")
93
    address = models.CharField(max_length=120, verbose_name=u"Adresse")
94
    address_complement = models.CharField(max_length=120, blank=True,
95
            null=True, default=None, verbose_name=u"Adresse complémentaire")
96
    zip_code = models.CharField(max_length=8, verbose_name=u"Code postal")
97
    city = models.CharField(max_length=80, verbose_name=u"Ville")
98
    phone = models.CharField(max_length=30, verbose_name=u"Téléphone")
99
    fax = models.CharField(max_length=30,
100
            null=True, blank=True, verbose_name=u"Fax")
101
    email = models.EmailField(
102
            null=True, blank=True, verbose_name=u"Courriel")
103
    accounting_number = models.CharField(max_length=30,
104
             null=True, blank=True, verbose_name=u"Numéro de compte")
105
    correspondant = models.CharField(max_length=80, verbose_name=u"Correspondant")
106
    hc_invoice = models.ForeignKey('HealthCenter',
107
            verbose_name=u"Centre pour facturation (optionnel)",
108
            null=True, blank=True, default=None)
109

    
110
    def b2_000(self):
111
        '''
112
        renvoie le numéro destinataire selon la norme B2, type 000
113
        '''
114
        return DEST_TYPE[self.large_regime.code] + '000000' + self.large_regime.code[0:2] + self.computer_center_code[0:3] + self.dest_organism[0:3]
115

    
116

    
117
class LargeRegime(NamedAbstractModel):
118
    class Meta:
119
        verbose_name = u'Grand régime'
120
        verbose_name_plural = u'Grands régimes'
121

    
122
    def __unicode__(self):
123
        return self.code + ' ' + self.name
124

    
125
    code = models.CharField(verbose_name=u"Code grand régime",
126
            max_length=2)
127

    
128

    
129
class TransportCompany(NamedAbstractModel):
130
    description = models.TextField(blank=True, null=True, default=None)
131
    address = models.CharField(max_length=120,
132
            verbose_name=u"Adresse", blank=True, null=True, default=None)
133
    address_complement = models.CharField(max_length=120,
134
            blank=True,
135
            null=True,
136
            default=None,
137
            verbose_name=u"Complément d'adresse")
138
    zip_code = ZipCodeField(verbose_name=u"Code postal",
139
        blank=True, null=True, default=None)
140
    city = models.CharField(max_length=80, verbose_name=u"Ville",
141
        blank=True, null=True, default=None)
142
    phone = PhoneNumberField(verbose_name=u"Téléphone",
143
        blank=True, null=True, default=None)
144
    fax = models.CharField(max_length=30,
145
            blank=True, null=True, default=None)
146
    email = models.EmailField(blank=True, null=True)
147
    correspondant = models.CharField(max_length=80, blank=True, null=True)
148
    old_camsp_id = models.CharField(max_length=256,
149
            verbose_name=u'Ancien ID au CAMSP', blank=True, null=True)
150
    old_cmpp_id = models.CharField(max_length=256,
151
            verbose_name=u'Ancien ID au CMPP', blank=True, null=True)
152
    old_sessad_dys_id = models.CharField(max_length=256,
153
            verbose_name=u'Ancien ID au SESSAD TED', blank=True, null=True)
154
    old_sessad_ted_id = models.CharField(max_length=256,
155
            verbose_name=u'Ancien ID au SESSAD DYS', blank=True, null=True)
156

    
157
    class Meta:
158
        verbose_name = u'Compagnie de transport'
159
        verbose_name_plural = u'Compagnies de transport'
160

    
161

    
162
class ManagementCode(NamedAbstractModel):
163
    class Meta:
164
        verbose_name = u'Code de gestion'
165
        verbose_name_plural = u'Codes de gestion'
166

    
167
    def __unicode__(self):
168
        return self.code + ' ' + self.name
169

    
170
    code = models.CharField(verbose_name=u"Code",
171
            max_length=10)
172
    old_id = models.CharField(max_length=256,
173
            verbose_name=u'Ancien ID', blank=True, null=True)
174

    
175

    
176
class UninvoicableCode(models.Model):
177
    class Meta:
178
        verbose_name = u'Code de non-facturation'
179
        verbose_name_plural = u'Codes de non-facturation'
180

    
181

    
182
class Office(NamedAbstractModel):
183
    class Meta:
184
        verbose_name = u'Établissement'
185
        verbose_name_plural = u'Établissements'
186

    
187
    def __unicode__(self):
188
        return self.name
189

    
190
    description = models.TextField(blank=True, null=True)
191

    
192
    # Contact
193
    phone = PhoneNumberField(verbose_name=u"Téléphone", blank=True, null=True)
194
    fax = PhoneNumberField(verbose_name=u"Fax", blank=True, null=True)
195
    email = models.EmailField(blank=True, null=True)
196

    
197
    # Address
198
    address = models.CharField(max_length=120,
199
            verbose_name=u"Adresse", blank=True, null=True, default=None)
200
    address_complement = models.CharField(max_length=120,
201
            blank=True,
202
            null=True,
203
            default=None,
204
            verbose_name=u"Complément d'adresse")
205
    zip_code = ZipCodeField(verbose_name=u"Code postal",
206
            blank=True, null=True, default=None)
207
    city = models.CharField(max_length=80, verbose_name=u"Ville",
208
            blank=True, null=True, default=None)
209

    
210
    # TODO: add this fields : finess, suite, dm, dpa, genre, categorie, statut_juridique, mft, mt, dmt
211

    
212
class SchoolType(NamedAbstractModel):
213
    class Meta:
214
        verbose_name = u'Type du lieu de socialisation'
215
        verbose_name_plural = u'Types du lieu de socialisation'
216

    
217
    services = models.ManyToManyField('ressources.Service')
218

    
219
class School(NamedAbstractModel):
220
    class Meta:
221
        verbose_name = u'Lieu de socialisation'
222
        verbose_name_plural = u'Lieux de socialisation'
223

    
224
    def __unicode__(self):
225
        if self.school_type.name != 'Inconnu':
226
            return unicode(self.school_type) + ' ' + self.name
227
        return self.name
228

    
229
    def save(self, **kwargs):
230
        self.display_name = ""
231
        if self.school_type.name != 'Inconnu':
232
            self.display_name = unicode(self.school_type) + ' ' + self.name
233
        else:
234
            self.display_name = self.name
235
        if self.address:
236
            self.display_name += u" - "  + self.address
237
        if self.zip_code:
238
            self.display_name += u" "  + self.zip_code
239
        if self.city:
240
            self.display_name += u" "  + self.city
241
        if self.private:
242
            self.display_name += u" (Privé)"
243
        else:
244
            self.display_name += u" (Public)"
245
        super(School, self).save(**kwargs)
246

    
247
    display_name = models.CharField(max_length=256,
248
            blank=True, null=True, default='')
249
    school_type = models.ForeignKey('ressources.SchoolType',
250
        verbose_name=u"Type d'établissement")
251
    description = models.TextField(blank=True, null=True, default=None)
252
    address = models.CharField(max_length=120,
253
            verbose_name=u"Adresse", blank=True, null=True, default=None)
254
    address_complement = models.CharField(max_length=120,
255
            blank=True,
256
            null=True,
257
            default=None,
258
            verbose_name=u"Complément d'adresse")
259
    zip_code = ZipCodeField(verbose_name=u"Code postal",
260
        blank=True, null=True, default=None)
261
    city = models.CharField(max_length=80, verbose_name=u"Ville",
262
        blank=True, null=True, default=None)
263
    phone = PhoneNumberField(verbose_name=u"Téléphone",
264
        blank=True, null=True, default=None)
265
    fax = models.CharField(max_length=30,
266
            blank=True, null=True, default=None)
267
    email = models.EmailField(blank=True, null=True, default=None)
268
    director_name = models.CharField(max_length=70,
269
            blank=True, null=True, default=None,
270
            verbose_name=u"Nom du directeur")
271
    old_id = models.CharField(max_length=256,
272
            verbose_name=u'Ancien ID', blank=True, null=True)
273
    old_service = models.CharField(max_length=256,
274
            verbose_name=u'Ancien Service', blank=True, null=True)
275
    private = models.BooleanField(verbose_name=u"Privé", default=False)
276
    services = models.ManyToManyField('ressources.Service', blank=True, null=True)
277

    
278

    
279
class SchoolTeacherRole(NamedAbstractModel):
280
    class Meta:
281
        verbose_name = u'Type de rôle des professeurs'
282
        verbose_name_plural = u'Types de rôle des professeurs'
283

    
284

    
285
class SchoolLevel(NamedAbstractModel):
286
    old_id = models.CharField(max_length=256,
287
            verbose_name=u'Ancien ID', blank=True, null=True)
288
    old_service = models.CharField(max_length=256,
289
            verbose_name=u'Ancien Service', blank=True, null=True)
290

    
291
    class Meta:
292
        verbose_name = u'Classe'
293
        verbose_name_plural = u'Classes'
294

    
295

    
296
class SocialisationDuration(models.Model):
297
    class Meta:
298
        verbose_name = u'Période de socialisation'
299
        verbose_name_plural = u'Périodes de socialisation'
300

    
301
    school = models.ForeignKey('ressources.School',
302
        verbose_name=u'Lieu de socialisation',
303
        blank=True, null=True)
304
    level = models.ForeignKey('ressources.SchoolLevel',
305
        verbose_name=u'Classe',
306
        blank=True, null=True)
307
    redoublement = models.BooleanField(verbose_name=u"Redoublement",
308
            default=False)
309
    start_date = models.DateField(verbose_name=u"Date d'arrivée")
310
    contact = models.CharField(verbose_name=u"Contact", max_length=200, blank=True, null=True, default=None)
311
    end_date = models.DateField(verbose_name=u"Date de départ",
312
        blank=True, null=True)
313
    created = models.DateTimeField(u'Création', auto_now_add=True)
314
    comment = models.TextField(max_length=3000,
315
        blank=True, null=True, verbose_name=u"Commentaire")
316

    
317

    
318
class InscriptionMotive(NamedAbstractModel):
319
    class Meta:
320
        verbose_name = u'Motif d\'inscription'
321
        verbose_name_plural = u'Motifs d\'inscription'
322

    
323

    
324
class Nationality(NamedAbstractModel):
325
    class Meta:
326
        verbose_name = u'Nationalité'
327
        verbose_name_plural = u'Nationalités'
328

    
329

    
330
class Job(NamedAbstractModel):
331
    class Meta:
332
        verbose_name = u'Profession'
333
        verbose_name_plural = u'Professions'
334

    
335

    
336
class RessourceQuerySet(query.QuerySet):
337
    def for_etablissement(self, etablissement):
338
        return self.filter(etablissement=etablissement)
339

    
340
    def for_service(self, service):
341
        return self.filter(etablissement__service=service)
342

    
343

    
344
class Ressource(NamedAbstractModel):
345
    objects = PassThroughManager.for_queryset_class(RessourceQuerySet)()
346
    etablissement = models.ForeignKey('Office')
347

    
348
    class Meta:
349
        verbose_name = u'Ressource'
350
        verbose_name_plural = u'Ressources'
351

    
352

    
353
class AnalyseMotive(NamedAbstractModel):
354
    class Meta:
355
        verbose_name = u"Motif analysé"
356
        verbose_name_plural = u"Motifs analysés"
357

    
358

    
359
class FamilyMotive(NamedAbstractModel):
360
    class Meta:
361
        verbose_name = u"Motif familiale"
362
        verbose_name_plural = u"Motifs familiaux"
363

    
364

    
365
class AdviceGiver(NamedAbstractModel):
366
    class Meta:
367
        verbose_name = u"Demandeur"
368
        verbose_name_plural = u"Demandeurs"
369

    
370

    
371
class Provenance(NamedAbstractModel):
372
    old_id = models.CharField(max_length=256,
373
            verbose_name=u'Ancien ID', blank=True, null=True)
374
    old_service = models.CharField(max_length=256,
375
            verbose_name=u'Ancien Service', blank=True, null=True)
376
    class Meta:
377
        verbose_name = u'Conseilleur'
378
        verbose_name_plural = u'Conseilleurs'
379

    
380

    
381
class ProvenancePlace(NamedAbstractModel):
382
    class Meta:
383
        verbose_name = u'Lieu de provenance'
384
        verbose_name_plural = u'Lieux de provenance'
385

    
386

    
387
class OutMotive(NamedAbstractModel):
388
    class Meta:
389
        verbose_name = u"Motif de sortie"
390
        verbose_name_plural = u"Motifs de sortie"
391

    
392

    
393
class OutTo(NamedAbstractModel):
394
    class Meta:
395
        verbose_name = u"Orientation de sortie"
396
        verbose_name_plural = u"Orientations de sortie"
397

    
398

    
399
class Service(NamedAbstractModel):
400
    admin_only = True
401

    
402
    slug = models.SlugField()
403
    description = models.TextField()
404

    
405
    # Contact
406
    phone = PhoneNumberField(verbose_name=u"Téléphone")
407
    fax = PhoneNumberField(verbose_name=u"Fax")
408
    email = models.EmailField()
409

    
410
    class Meta:
411
        verbose_name = u'Service'
412
        verbose_name_plural = u'Services'
413

    
414

    
415
class ActTypeQuerySet(query.QuerySet):
416
    def for_service(self, service):
417
        return self.filter(service=service)
418

    
419
class ActType(NamedAbstractModel, ServiceLinkedAbstractModel):
420
    objects = PassThroughManager.for_queryset_class(ActTypeQuerySet)()
421
    billable = models.BooleanField(default=True, verbose_name=u"Facturable")
422
    old_id = models.CharField(max_length=256,
423
            verbose_name=u'Ancien ID', blank=True, null=True)
424
    display_first = models.BooleanField(default=False, verbose_name=u"Acte principalement utilisé")
425
    group = models.BooleanField(default=False, verbose_name=u'De groupe')
426

    
427
    class Meta(NamedAbstractModel.Meta):
428
        verbose_name = u'Type d\'actes'
429
        verbose_name_plural = u'Types d\'actes'
430
        ordering = ('-display_first','name')
431

    
432
class ParentalAuthorityType(NamedAbstractModel):
433
    class Meta:
434
        verbose_name = u'Type d\'autorité parentale'
435
        verbose_name_plural = u'Types d\'autorités parentales'
436

    
437

    
438
class ParentalCustodyType(NamedAbstractModel):
439
    class Meta:
440
        verbose_name = u'Type de gardes parentales'
441
        verbose_name_plural = u'Types de gardes parentales'
442

    
443

    
444
class SessionType(NamedAbstractModel):
445
    class Meta:
446
        verbose_name = u'Type de séance'
447
        verbose_name_plural = u'Types de séances'
448

    
449

    
450
class FamilySituationType(NamedAbstractModel):
451
    class Meta:
452
        verbose_name = u'Type de situation familiale'
453
        verbose_name_plural = u'Types de situations familiales'
454

    
455

    
456
class MaritalStatusType(NamedAbstractModel):
457
    class Meta:
458
        verbose_name = u'Régime matrimonial'
459
        verbose_name_plural = u'Régimes matrimoniaux'
460

    
461

    
462
class TransportType(NamedAbstractModel):
463
    class Meta:
464
        verbose_name = u'Type de transport'
465
        verbose_name_plural = u'Types de transports'
466

    
467

    
468
class WorkerType(NamedAbstractModel):
469
    intervene = models.BooleanField(
470
            verbose_name=u'Intervenant',
471
            blank=True)
472

    
473
    class Meta:
474
        verbose_name = u'Type de personnel'
475
        verbose_name_plural = u'Types de personnel'
476

    
477

    
478
AXIS =  Choices(
479
        (1, 'Axe I : catégories cliniques'),
480
        (2, 'Axe II : facteurs organiques'),
481
        (3, 'Axe II : facteurs environnementaux'),
482
)
483

    
484
class CodeCFTMEA(NamedAbstractModel):
485
    code = models.IntegerField(verbose_name=u"Code")
486
    axe = models.IntegerField(verbose_name=u"Axe", choices=AXIS,
487
            max_length=1)
488
    ordering_code = models.CharField(max_length=20, blank=True, null=True,
489
            verbose_name=u"Classification")
490

    
491
    def __unicode__(self):
492
        return "%s %s" % (self.ordering_code, self.name)
493

    
494
    class Meta:
495
        ordering = ['ordering_code']
496
        verbose_name = u'Code CFTMEA'
497
        verbose_name_plural = u'Codes CFTMEA'
498

    
499
class MDPH(models.Model):
500
    class Meta:
501
        verbose_name = u'Etablissement MDPH'
502
        verbose_name_plural = u'Etablissements MDPH'
503

    
504
    def __unicode__(self):
505
        return self.department
506

    
507
    department = models.CharField(max_length=200,
508
            verbose_name=u"Département")
509

    
510
    description = models.TextField(blank=True, null=True)
511

    
512
    # Contact
513
    phone = PhoneNumberField(verbose_name=u"Téléphone", blank=True, null=True)
514
    fax = PhoneNumberField(verbose_name=u"Fax", blank=True, null=True)
515
    email = models.EmailField(blank=True, null=True)
516
    website = models.CharField(max_length=200,
517
            verbose_name=u"Site Web", blank=True, null=True)
518

    
519
    # Address
520
    address = models.CharField(max_length=120,
521
            verbose_name=u"Adresse", blank=True, null=True)
522
    address_complement = models.CharField(max_length=120,
523
            blank=True,
524
            null=True,
525
            default=None,
526
            verbose_name=u"Complément d'addresse")
527
    zip_code = ZipCodeField(verbose_name=u"Code postal",
528
        blank=True, null=True)
529
    city = models.CharField(max_length=80,
530
            verbose_name=u"Ville", blank=True, null=True)
531

    
532
class MDPHRequest(models.Model):
533
    class Meta:
534
        verbose_name = u'Demande MDPH'
535
        verbose_name_plural = u'Demandes MDPH'
536

    
537
    start_date = models.DateField(verbose_name=u"Date de la demande")
538
    mdph = models.ForeignKey('ressources.MDPH',
539
            verbose_name=u"MDPH")
540
    comment = models.TextField(max_length=3000,
541
        blank=True, null=True, verbose_name=u"Commentaire")
542
    created = models.DateTimeField(u'Création', auto_now_add=True)
543

    
544
MDPH_HELP =  Choices(
545
        (0, "Non défini"),
546
        (1, "AEEH (Allocation d'éducation de l'enfant handicapé)"),
547
        (2, 'AVS (Assistant de vie scolaire)'),
548
        (3, 'EVS (Emplois de vie scolaire)'),
549
)
550

    
551
class MDPHResponse(models.Model):
552
    class Meta:
553
        verbose_name = u'Réponse MDPH'
554
        verbose_name_plural = u'Réponses MDPH'
555

    
556
    start_date = models.DateField(verbose_name=u"Date de début")
557
    end_date = models.DateField(verbose_name=u"Date de fin")
558
    mdph = models.ForeignKey('ressources.MDPH',
559
            verbose_name=u"MDPH")
560
    comment = models.TextField(max_length=3000,
561
        blank=True, null=True, verbose_name=u"Commentaire")
562
    created = models.DateTimeField(u'Création', auto_now_add=True)
563
    type_aide = models.IntegerField(verbose_name=u"Type d'aide", choices=MDPH_HELP,
564
            max_length=1, default=0)
565
    name =  models.CharField(max_length=200,
566
            verbose_name=u"Nom", blank=True, null=True)
567
    rate =  models.CharField(max_length=10,
568
            verbose_name=u"Taux", blank=True, null=True)
569

    
570

    
571
class HolidayType(NamedAbstractModel):
572
    for_group = models.BooleanField(
573
            verbose_name=u'Absence de groupe',
574
            blank=True)
575

    
576
    class Meta:
577
        verbose_name = u"Type d'absence"
578
        verbose_name_plural = u"Types d'absence"
579

    
580
class PatientRelatedLink(NamedAbstractModel):
581
    old_camsp_id = models.CharField(max_length=256,
582
            verbose_name=u'Ancien ID au CAMSP', blank=True, null=True)
583
    old_cmpp_id = models.CharField(max_length=256,
584
            verbose_name=u'Ancien ID au CMPP', blank=True, null=True)
585
    old_sessad_dys_id = models.CharField(max_length=256,
586
            verbose_name=u'Ancien ID au SESSAD TED', blank=True, null=True)
587
    old_sessad_ted_id = models.CharField(max_length=256,
588
            verbose_name=u'Ancien ID au SESSAD DYS', blank=True, null=True)
589
    class Meta:
590
        verbose_name = u'Type de lien avec le patient (parenté)'
591
        verbose_name_plural = u'Types de lien avec le patient (parenté)'
592

    
593
class PricePerAct(models.Model):
594
    price = models.DecimalField(verbose_name=u"Tarif", max_digits=5, decimal_places=2)
595
    start_date = models.DateField(verbose_name=u"Prise d'effet")
596

    
597
    class Pricing(object):
598
        def __init__(self, ppas):
599
            ppas = ppas.order_by('start_date')
600
            self.dates = [ppa.start_date for ppa in ppas]
601
            self.ppas = list(ppas)
602

    
603
        def price_at_date(self, date):
604
            i = bisect.bisect(self.dates, date)
605
            if i == 0:
606
                raise RuntimeError('No existing price at date %s' % date)
607
            return self.ppas[i-1].price
608

    
609
    class Meta:
610
        verbose_name = u"Tarif horaire de l'acte"
611
        verbose_name_plural = u"Tarifs horaires de l'acte"
612

    
613
    @classmethod
614
    def pricing(cls):
615
        return cls.Pricing(cls.objects.all())
616

    
617
    @classmethod
618
    def get_price(cls, at_date=None):
619
        if not at_date:
620
            at_date = date.today()
621
        if isinstance(at_date, datetime):
622
            at_date = date(day=at_date.day, month=at_date.month,
623
                year=at_date.year)
624
        found = cls.objects.filter(start_date__lte = at_date).latest('start_date')
625
        if not found:
626
            raise Exception('No price to apply')
627
        return found.price
628

    
629
    def __unicode__(self):
630
        return str(self.price) + ' (' + str(self.start_date) + ')'
(4-4/7)