agenda: don't allow a periodicity to end before last billed act

Fixes #2929
This commit is contained in:
Jérôme Schneider 2013-07-16 16:27:28 +02:00
parent b22ecaafb8
commit 7af04d52f4
3 changed files with 20 additions and 6 deletions

View File

@ -11,7 +11,6 @@ class Appointment(object):
def __init__(self, title=None, begin_time=None, type=None,
length=None, description=None, room=None):
""" """
self.title = title
self.type = type
self.length = length

View File

@ -1,3 +1,4 @@
import ipdb
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
@ -92,8 +93,21 @@ class NewAppointmentForm(BaseForm):
class UpdatePeriodicAppointmentForm(NewAppointmentForm):
def is_valid(self):
acts = self.instance.act_set.filter(is_billed=True).order_by('-date')
if acts and self.data.get('recurrence_end_date'):
recurrence_end_date = datetime.strptime(self.data['recurrence_end_date'],
'%d/%m/%Y').date()
if recurrence_end_date < acts[0].date:
self.errors['recurrence_end_date'] = \
u"La date doit être supérieur au dernier acte de la récurrence facturée"
return False
return super(UpdatePeriodicAppointmentForm, self).is_valid()
class DisablePatientAppointmentForm(NewAppointmentForm):
def __init__(self, instance, service=None, **kwargs):
super(UpdatePeriodicAppointmentForm, self).__init__(instance,
super(DisablePatientAppointmentForm, self).__init__(instance,
service, **kwargs)
if instance and instance.pk:
self.fields['patient'].required = False

View File

@ -23,8 +23,8 @@ from calebasse.actes.validation import (automated_validation, unlock_all_acts_of
from calebasse import cbv
from forms import (NewAppointmentForm, NewEventForm, UpdatePeriodicAppointmentForm,
UpdateAppointmentForm, UpdateEventForm, PeriodicEventsSearchForm)
DisablePatientAppointmentForm, UpdateAppointmentForm,
UpdateEventForm, PeriodicEventsSearchForm)
def redirect_today(request, service):
'''If not date is given we redirect on the agenda for today'''
@ -187,15 +187,16 @@ class UpdateAppointmentView(TodayOccurrenceMixin, BaseAppointmentView):
def get_form_class(self):
if self.object.exception_to and not self.object.exception_to.canceled:
return UpdatePeriodicAppointmentForm
return DisablePatientAppointmentForm
else:
return self.form_class
class UpdatePeriodicAppointmentView(BaseAppointmentView):
form_class = NewAppointmentForm
form_class = UpdatePeriodicAppointmentForm
template_name = 'agenda/new-appointment.html'
class NewEventView(CreateView):
model = Event
form_class = NewEventForm