Projet

Général

Profil

« Précédent | Suivant » 

Révision a2e49cca

Ajouté par Mikaël Ates il y a plus de 9 ans

agenda: prevent periodic modification and deletion if one act is not new.

Voir les différences:

calebasse/agenda/forms.py
156 156
            choices=Event.PERIODICITIES, required=True)
157 157

  
158 158
    def clean(self):
159
        '''
160
            Check that reccurrency bound dates
161
            won't exclude already_billed acts.
162
        '''
163 159
        cleaned_data = super(UpdatePeriodicAppointmentForm, self).clean()
160
        '''If one act not new in the reccurrence, we prevent to modify the
161
        start date or the recurrence_periodicity since this could trigger act
162
        deletion'''
164 163
        start_datetime = cleaned_data.get('start_datetime')
165
        if start_datetime:
166
            acts = Act.objects.filter(
167
                Q(parent_event=self.instance,
168
                    already_billed=True, date__lt=start_datetime) | \
169
                Q(parent_event__exception_to=self.instance,
170
                    already_billed=True, date__lt=start_datetime))
171
            if acts:
172
                self._errors['start_datetime'] = self.error_class([
173
                    u"La date de début doit être antérieure au premier acte déja facturé de la récurrence"])
164
        if start_datetime and start_datetime != self.instance.start_datetime \
165
                and self.instance.one_act_not_new():
166
            self._errors['start_datetime'] = self.error_class([
167
                u"La date de début ne peut-être modifiée car un acte de la récurrence est pointé"])
168
#       FIXME
169
#        recurrence_periodicity = cleaned_data.get('recurrence_periodicity')
170
#        if recurrence_periodicity and recurrence_periodicity != str(self.instance.recurrence_periodicity) \
171
#                and self.instance.one_act_not_new():
172
#            self._errors['recurrence_periodicity'] = self.error_class([
173
#                u"La récurrence ne peut-être modifiée car un acte de la récurrence est pointé"])
174
        '''We check that the end date is posterior to the last act not new'''
174 175
        recurrence_end_date = cleaned_data.get('recurrence_end_date')
175
        if recurrence_end_date:
176
            acts = Act.objects.filter(
177
                Q(parent_event=self.instance,
178
                    already_billed=True, date__gt=recurrence_end_date) | \
179
                Q(parent_event__exception_to=self.instance,
180
                    already_billed=True, date__gt=recurrence_end_date))
181
            if acts:
176
        if recurrence_end_date and recurrence_end_date != self.instance.recurrence_end_date \
177
                and self.instance.one_act_not_new():
178
            last = self.instance.last_act_not_new()
179
            if last and last.date > recurrence_end_date:
182 180
                self._errors['recurrence_end_date'] = self.error_class([
183
                    u"La date de fin doit être postérieure au dernier acte déja facturé de la récurrence"])
181
                    u"La date de fin doit être postérieure au dernier acte pointé de la récurrence (%s)" % last])
184 182
        return cleaned_data
185 183

  
186 184
class DisablePatientAppointmentForm(UpdateAppointmentForm):
calebasse/agenda/models.py
395 395
                models.Q(parent_event=self) | \
396 396
                models.Q(parent_event__exception_to=self))
397 397

  
398
    def one_act_not_new(self):
399
        '''
400
            Return True if at least one act of the present event or an act
401
            of one of its exceptions is not new.
402
        '''
403
        return True if [a for a in self.acts if not a.is_new()] else False
404

  
405
    def last_act_not_new(self):
406
        '''
407
            Return True if at least one act of the present event or an act
408
            of one of its exceptions is not new.
409
        '''
410
        act = None
411
        for a in self.acts:
412
            if not a.is_new():
413
                if not act or a.date > act.date:
414
                    act = a
415
        return act
416

  
398 417
    def one_act_already_billed(self):
399 418
        '''
400 419
            Return True if at least one act of the present event or an act
calebasse/agenda/templates/agenda/appointment.html
3 3
{{ form.non_field_errors }}
4 4
{{ form.start_datetime }}
5 5
{{ form.start_datetime.errors }}
6
   {% if object.is_recurring and object.one_act_is_billed %}<p><em>Le rendez-vous périodique a un acte qui est facturé ce qui empêche de le modifier à l'exception de la description, de la ressource et des dates de début et de fin.</em></p>{% endif %}
7
   {% if object.is_recurring and object.one_act_already_billed %}<p><em>Le rendez-vous périodique a un acte qui a déjà été facturé ce qui empêche de le supprimer.</em></p>{% endif %}
6
   {% if object.is_recurring and object.one_act_not_new %}<p><em>Le rendez-vous périodique a un acte qui est pointé ce qui empêche de le modifier à l'exception de la description, de la ressource et de la date de fin.</em></p>{% endif %}
7
   {% if object.is_recurring and object.one_act_not_new %}<p><em>Le rendez-vous périodique a un acte qui est pointé ce qui empêche de le supprimer.</em></p>{% endif %}
8 8
   <table id="new-appointment-table">
9 9
       <tr>
10 10
           <td {% if form.time.field.required %}class="required"{% endif %}>
11 11
            <p>
12 12
           {{ form.time.label_tag }}
13
           {% if object.is_recurring and object.one_act_is_billed %}
13
           {% if object.is_recurring and object.one_act_not_new %}
14 14
           {{ object.time }}
15 15
           {{ form.time.as_hidden }}
16 16
           {% else %}
......
22 22
           <td {% if form.duration.field.required %}class="required"{% endif %}>
23 23
           <p>
24 24
           {{ form.duration.label_tag }}
25
           {% if object.is_recurring and object.one_act_is_billed %}
25
           {% if object.is_recurring and object.one_act_not_new %}
26 26
           {{ object.duration }}
27 27
           {{ form.duration.as_hidden }}
28 28
           {% else %}
......
34 34
           <td {% if form.date.field.required %}class="required"{% endif %}>
35 35
           <p class="datepicker">
36 36
           {{ form.date.label_tag }}
37
           {% if object.is_recurring and object.one_act_not_new %}
38
           {{ object.date }}
39
           {{ form.date.as_hidden }}
40
           {% else %}
37 41
           {{ form.date|add_class:"datepicker-date" }}
42
           {% endif %}
38 43
           {{ form.date.errors }}
39 44
           </p>
40 45
           </td>
......
52 57
           <td {% if form.participants.field.required %}class="required"{% endif %}>
53 58
           <h4>{{ form.participants.label_tag }}</h4>
54 59
           <div id="intervenants">
55
           {% if object.is_recurring and object.one_act_is_billed %}
60
           {% if object.is_recurring and object.one_act_not_new %}
56 61
           <ul>{% for p in object.participants.all %}<li>{{ p }}</li>{% endfor %}</ul>
57 62
           <input id="id_participants" name="participants" value="|{% for p in object.participants.all %}{{ p.id }}|{% endfor %}" type="hidden"/>
58 63
           {% else %}
......
75 80
           </td>
76 81
           <td {% if form.act_type.field.required %}class="required"{% endif %}>
77 82
           <h4>{{ form.act_type.label_tag }}</h4>
78
           {% if object.is_recurring and object.one_act_is_billed %}
83
           {% if object.is_recurring and object.one_act_not_new %}
79 84
           {{ object.act_type }}
80 85
           {{ form.act_type.as_hidden }}
81 86
           {% else %}
......
108 113
    {{ object.exception_to.recurrence_description|lower }}</p>
109 114

  
110 115
  {% if not object.exception_to.canceled %}
111
  <p><button type="button" data-delete-url="{% url 'delete-event' service=service date=date pk=object.exception_to.pk %}" data-id="{{ object.exception_to.id }}" data-one_act_already_billed="{{ object.exception_to.one_act_already_billed }}"  class="update-periodic-rdv">Éditer le rendez-vous périodique</button></p>
116
  <p><button type="button" data-delete-url="{% url 'delete-event' service=service date=date pk=object.exception_to.pk %}" data-id="{{ object.exception_to.id }}" data-one_act_not_new="{{ object.exception_to.one_act_not_new }}"  class="update-periodic-rdv">Éditer le rendez-vous périodique</button></p>
112 117
  {% endif %}
113 118

  
114 119
{% endif %}
calebasse/agenda/templates/agenda/periodicity.html
4 4
           <td {% if form.recurrence_periodicity.field.required %}class="required"{% endif %}>
5 5
            <p>
6 6
           {{ form.recurrence_periodicity.label_tag }}
7
           {% if object.one_act_already_billed %}
7
           {% if object.one_act_not_new %}
8 8
           {{ object.recurrence_description }}
9 9
           {{ form.recurrence_periodicity.as_hidden }}
10 10
           {% else %}
calebasse/static/js/calebasse.agenda.js
280 280
      $(base).on('click', '.update-periodic-rdv', function (event) {
281 281
        $('.ui-icon-closethick').click();
282 282
        var id = $(this).data('id');
283
        var one_act_already_billed = $(this).data('one_act_already_billed');
283
        var one_act_not_new = $(this).data('one_act_not_new');
284 284
        var delete_button = null;
285
        if (one_act_already_billed == 'False') {
285
        if (one_act_not_new == 'False') {
286 286
            var delete_url = $(this).data('delete-url');
287 287
            var delete_button = {
288 288
                text: "Supprimer",

Formats disponibles : Unified diff