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

This commit is contained in:
Mikaël Ates 2014-09-26 18:39:14 +02:00
parent c7a7ddf674
commit a2e49cca18
5 changed files with 53 additions and 31 deletions

View File

@ -156,31 +156,29 @@ class UpdatePeriodicAppointmentForm(UpdateAppointmentForm):
choices=Event.PERIODICITIES, required=True)
def clean(self):
'''
Check that reccurrency bound dates
won't exclude already_billed acts.
'''
cleaned_data = super(UpdatePeriodicAppointmentForm, self).clean()
'''If one act not new in the reccurrence, we prevent to modify the
start date or the recurrence_periodicity since this could trigger act
deletion'''
start_datetime = cleaned_data.get('start_datetime')
if start_datetime:
acts = Act.objects.filter(
Q(parent_event=self.instance,
already_billed=True, date__lt=start_datetime) | \
Q(parent_event__exception_to=self.instance,
already_billed=True, date__lt=start_datetime))
if acts:
self._errors['start_datetime'] = self.error_class([
u"La date de début doit être antérieure au premier acte déja facturé de la récurrence"])
if start_datetime and start_datetime != self.instance.start_datetime \
and self.instance.one_act_not_new():
self._errors['start_datetime'] = self.error_class([
u"La date de début ne peut-être modifiée car un acte de la récurrence est pointé"])
# FIXME
# recurrence_periodicity = cleaned_data.get('recurrence_periodicity')
# if recurrence_periodicity and recurrence_periodicity != str(self.instance.recurrence_periodicity) \
# and self.instance.one_act_not_new():
# self._errors['recurrence_periodicity'] = self.error_class([
# u"La récurrence ne peut-être modifiée car un acte de la récurrence est pointé"])
'''We check that the end date is posterior to the last act not new'''
recurrence_end_date = cleaned_data.get('recurrence_end_date')
if recurrence_end_date:
acts = Act.objects.filter(
Q(parent_event=self.instance,
already_billed=True, date__gt=recurrence_end_date) | \
Q(parent_event__exception_to=self.instance,
already_billed=True, date__gt=recurrence_end_date))
if acts:
if recurrence_end_date and recurrence_end_date != self.instance.recurrence_end_date \
and self.instance.one_act_not_new():
last = self.instance.last_act_not_new()
if last and last.date > recurrence_end_date:
self._errors['recurrence_end_date'] = self.error_class([
u"La date de fin doit être postérieure au dernier acte déja facturé de la récurrence"])
u"La date de fin doit être postérieure au dernier acte pointé de la récurrence (%s)" % last])
return cleaned_data
class DisablePatientAppointmentForm(UpdateAppointmentForm):

View File

@ -395,6 +395,25 @@ class Event(models.Model):
models.Q(parent_event=self) | \
models.Q(parent_event__exception_to=self))
def one_act_not_new(self):
'''
Return True if at least one act of the present event or an act
of one of its exceptions is not new.
'''
return True if [a for a in self.acts if not a.is_new()] else False
def last_act_not_new(self):
'''
Return True if at least one act of the present event or an act
of one of its exceptions is not new.
'''
act = None
for a in self.acts:
if not a.is_new():
if not act or a.date > act.date:
act = a
return act
def one_act_already_billed(self):
'''
Return True if at least one act of the present event or an act

View File

@ -3,14 +3,14 @@
{{ form.non_field_errors }}
{{ form.start_datetime }}
{{ form.start_datetime.errors }}
{% 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 %}
{% 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 %}
{% 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 %}
{% 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 %}
<table id="new-appointment-table">
<tr>
<td {% if form.time.field.required %}class="required"{% endif %}>
<p>
{{ form.time.label_tag }}
{% if object.is_recurring and object.one_act_is_billed %}
{% if object.is_recurring and object.one_act_not_new %}
{{ object.time }}
{{ form.time.as_hidden }}
{% else %}
@ -22,7 +22,7 @@
<td {% if form.duration.field.required %}class="required"{% endif %}>
<p>
{{ form.duration.label_tag }}
{% if object.is_recurring and object.one_act_is_billed %}
{% if object.is_recurring and object.one_act_not_new %}
{{ object.duration }}
{{ form.duration.as_hidden }}
{% else %}
@ -34,7 +34,12 @@
<td {% if form.date.field.required %}class="required"{% endif %}>
<p class="datepicker">
{{ form.date.label_tag }}
{% if object.is_recurring and object.one_act_not_new %}
{{ object.date }}
{{ form.date.as_hidden }}
{% else %}
{{ form.date|add_class:"datepicker-date" }}
{% endif %}
{{ form.date.errors }}
</p>
</td>
@ -52,7 +57,7 @@
<td {% if form.participants.field.required %}class="required"{% endif %}>
<h4>{{ form.participants.label_tag }}</h4>
<div id="intervenants">
{% if object.is_recurring and object.one_act_is_billed %}
{% if object.is_recurring and object.one_act_not_new %}
<ul>{% for p in object.participants.all %}<li>{{ p }}</li>{% endfor %}</ul>
<input id="id_participants" name="participants" value="|{% for p in object.participants.all %}{{ p.id }}|{% endfor %}" type="hidden"/>
{% else %}
@ -75,7 +80,7 @@
</td>
<td {% if form.act_type.field.required %}class="required"{% endif %}>
<h4>{{ form.act_type.label_tag }}</h4>
{% if object.is_recurring and object.one_act_is_billed %}
{% if object.is_recurring and object.one_act_not_new %}
{{ object.act_type }}
{{ form.act_type.as_hidden }}
{% else %}
@ -108,7 +113,7 @@
{{ object.exception_to.recurrence_description|lower }}</p>
{% if not object.exception_to.canceled %}
<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>
<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>
{% endif %}
{% endif %}

View File

@ -4,7 +4,7 @@
<td {% if form.recurrence_periodicity.field.required %}class="required"{% endif %}>
<p>
{{ form.recurrence_periodicity.label_tag }}
{% if object.one_act_already_billed %}
{% if object.one_act_not_new %}
{{ object.recurrence_description }}
{{ form.recurrence_periodicity.as_hidden }}
{% else %}

View File

@ -280,9 +280,9 @@ function event_dialog(url, title, width, btn_text) {
$(base).on('click', '.update-periodic-rdv', function (event) {
$('.ui-icon-closethick').click();
var id = $(this).data('id');
var one_act_already_billed = $(this).data('one_act_already_billed');
var one_act_not_new = $(this).data('one_act_not_new');
var delete_button = null;
if (one_act_already_billed == 'False') {
if (one_act_not_new == 'False') {
var delete_url = $(this).data('delete-url');
var delete_button = {
text: "Supprimer",