Project

General

Profile

« Previous | Next » 

Revision 046a69ee

Added by Benjamin Dauvergne over 12 years ago

agenda: update Act.parent_event when updating an Act from an EventWithAct

View differences:

calebasse/agenda/models.py
431 431
        act.doctors = self.participants.select_subclasses()
432 432
        act.act_type = self.act_type
433 433
        act.patient = self.patient
434
        act.parent_event = self
434 435
        act.date = self.start_datetime.date()
435 436
        act.save()
436 437

  
......
438 439
        '''Force event_type to be patient meeting.'''
439 440
        self.event_type = EventType(id=1)
440 441
        super(EventWithAct, self).save(*args, **kwargs)
441
        # list of occurences may have changed
442
        from ..actes.models import Act
443
        occurences = list(self.all_occurences())
444
        acts = Act.objects.filter(parent_event=self)
445
        occurences_by_date = dict((o.start_datetime.date(), o) for o in occurences)
446
        acts_by_date = dict()
447
        for a in acts:
448
            # sanity check
449
            assert a.date not in acts_by_date
450
            acts_by_date[a.date] = a
451
        for a in acts:
452
            o = occurences_by_date.get(a.date)
453
            if o:
454
                o.update_act(a)
455
            else:
456
                if len(a.actvalidationstate_set.all()) > 1:
457
                    a.parent_event = None
458
                    a.save()
459
                else:
460
                    a.delete()
461
        for o in occurences:
462
            if o.start_datetime.date() in acts_by_date:
463
                continue
464
            o.get_or_create_act()
465

  
466
    def today_occurrence(self, today=None, match=False, upgrade=True):
467
        '''For virtual occurrences reset the event_ptr_id'''
468
        occurrence = super(EventWithAct, self).today_occurrence(today, match, upgrade)
469
        if hasattr(occurrence, 'parent'):
470
            old_save = occurrence.save
471
            def save(*args, **kwargs):
472
                occurrence.event_ptr_id = None
473
                old_save(*args, **kwargs)
474
            occurrence.save = save
475
        return occurrence
476 442

  
477 443
    def is_event_absence(self):
478 444
        return self.act.is_absent()

Also available in: Unified diff