Revision a2e49cca
Added by Mikaël Ates about 10 years ago
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): |
Also available in: Unified diff
agenda: prevent periodic modification and deletion if one act is not new.