Projet

Général

Profil

« Précédent | Suivant » 

Révision b2ab5f4c

Ajouté par Mikaël Ates il y a presque 10 ans

agenda: various modification on periodicity management and heper functions and properties

Add date, time and duration to Event model.
Add acts property returning a queryset of the acts associated to the periodic Event
and associated to its exceptions.
Add one_act_already_billed and one_act_is_billed, existence tests on periodic Event
acts.
Add events_cleaning Event function run at saving to delete exceptions out of the
reccurrency bounds.
Modify acts_cleaning to protect act already_billed from deletion.
Modify init_act() EventWithAct method to prevent act synchronisation called by
acts_cleaning for billed acts.
Modify Event delete method to prevent deletion of Event with an already billed act.
If deletion is possible, run the delete on all the exception before setting self
canceled and saving.

Voir les différences:

calebasse/agenda/models.py
207 207
        '''Distance between start and end of the event'''
208 208
        return self.end_datetime - self.start_datetime
209 209

  
210
    @property
211
    def time(self):
212
        return self.start_datetime.time()
213

  
214
    @property
215
    def date(self):
216
        return self.start_datetime.date()
217

  
218
    @property
219
    def duration(self):
220
        if self.timedelta():
221
            return self.timedelta().seconds / 60
222
        return 0
223

  
210 224
    def match_date(self, date):
211 225
        if self.is_recurring():
212 226
            # consider exceptions
......
360 374
        assert self.start_datetime is not None
361 375
        self.sanitize() # init periodicity fields
362 376
        super(Event, self).save(*args, **kwargs)
377
        self.events_cleaning()
363 378
        self.acts_cleaning()
364 379

  
365 380
    def delete(self, *args, **kwargs):
366
        self.canceled = True
367
        # save will clean acts
368
        self.save(*args, **kwargs)
381
        if not self.one_act_already_billed():
382
            for exception in self.exceptions.all():
383
                exception.delete()
384
            self.canceled = True
385
            if hasattr(self, 'eventwithact'):
386
                # Needed
387
                self.eventwithact.canceled = True
388
            # save will clean acts
389
            self.save(*args, **kwargs)
390

  
391
    @property
392
    def acts(self):
393
        from ..actes.models import Act
394
        return Act.objects.filter(
395
                models.Q(parent_event=self) | \
396
                models.Q(parent_event__exception_to=self))
397

  
398
    def one_act_already_billed(self):
399
        '''
400
            Return True if at least one act of the present event or an act
401
            of one of its exceptions is already billed.
402
        '''
403
        return self.acts.filter(already_billed=True).exists()
404

  
405
    def one_act_is_billed(self):
406
        '''
407
            Return True if at least one act of the present event or an act
408
            of one of its exceptions is billed.
409
        '''
410
        return self.acts.filter(is_billed=True).exists()
411

  
412
    def events_cleaning(self):
413
        """
414
            Delete exceptions out of bounds if not with an associated act
415
            already billed.
416
        """
417
        events = None
418
        if self.recurrence_end_date:
419
            events = Event.objects.filter(
420
                models.Q(exception_to=self,
421
                    exception_date__lt=self.start_datetime.date()) | \
422
                models.Q(exception_to=self,
423
                    exception_date__gt=self.recurrence_end_date))
424
        else:
425
            events = Event.objects.filter(exception_to=self,
426
                    exception_date__lt=self.start_datetime.date())
427
        for event in events:
428
            if hasattr(event, 'eventwithact'):
429
                if not event.eventwithact.act.already_billed:
430
                    event.delete()
431
            else:
432
                event.delete()
369 433

  
370 434
    def acts_cleaning(self):
371 435
        # list of occurences may have changed
......
382 446
        if acts:
383 447
            eventwithact = self.eventwithact
384 448
            for act in acts:
385
                if act.is_billed:
386
                    pass
387 449
                occurrence = eventwithact.today_occurrence(act.date)
388 450
                if occurrence:
389 451
                    occurrence.update_act(act)
390 452
                else:
391
                    act.delete()
453
                    if not act.already_billed:
454
                        act.delete()
392 455

  
393 456
    def to_interval(self):
394 457
        return Interval(self.start_datetime, self.end_datetime)
......
538 601
        act.save()
539 602

  
540 603
    def init_act(self, act):
541
        delta = self.timedelta()
542
        duration = delta.seconds // 60
543
        act._duration = duration
544
        act.act_type = self.act_type
545
        act.patient = self.patient
604
        if not act.is_billed:
605
            delta = self.timedelta()
606
            duration = delta.seconds // 60
607
            act._duration = duration
608
            act.act_type = self.act_type
609
            act.patient = self.patient
610
            act.date = self.start_datetime.date()
611
            act.time = self.start_datetime.time()
546 612
        act.parent_event = self
547
        act.date = self.start_datetime.date()
548
        act.time = self.start_datetime.time()
549 613

  
550 614
    def save(self, *args, **kwargs):
551 615
        '''Force event_type to be patient meeting.'''

Formats disponibles : Unified diff