[IMP]GOLEM Resource check : better performance with pre-calculation and restricted domain search for conflicts
This commit is contained in:
parent
d5cc394967
commit
398a3e7f63
@ -176,22 +176,25 @@ class GolemResourceReservation(models.Model):
|
||||
is_day_allowed = True
|
||||
#only check if the day hasn't a 24 availibility
|
||||
if not timetable.availibility_24:
|
||||
hour_start = 0.0
|
||||
hour_stop = 0.0
|
||||
if (reservation_day.date() == date_start.date() and
|
||||
reservation_day.date() == date_stop.date()):
|
||||
reservation_day_date = reservation_day.date()
|
||||
day_start = date_start.date()
|
||||
day_stop = date_stop.date()
|
||||
if reservation_day_date == day_start and \
|
||||
reservation_day_date == day_stop:
|
||||
hour_start = date_start.hour + date_start.minute / 60.0
|
||||
hour_stop = date_stop.hour + date_stop.minute / 60.0
|
||||
elif reservation_day.date() == date_start.date():
|
||||
elif reservation_day_date == day_start:
|
||||
hour_start = date_start.hour + date_start.minute / 60.0
|
||||
hour_stop = 23.98
|
||||
elif reservation_day.date() == date_stop.date():
|
||||
hour_stop = 23.98 # Just before 23:59
|
||||
elif reservation_day_date == day_stop:
|
||||
hour_start = 0.0
|
||||
hour_stop = date_stop.hour + date_stop.minute / 60.0
|
||||
else:
|
||||
#if the day is not a start nor stop it's not allowed unless
|
||||
#availibility_24 is True
|
||||
is_day_allowed = False
|
||||
#if the day is not a start nor stop it
|
||||
#should be covered on all day
|
||||
#strange, as availibility_24 is not True
|
||||
hour_start = 0.0
|
||||
hour_stop = 23.98
|
||||
|
||||
if is_day_allowed and (hour_start < timetable.time_start or \
|
||||
hour_stop > timetable.time_stop):
|
||||
@ -201,10 +204,15 @@ class GolemResourceReservation(models.Model):
|
||||
raise ValidationError(verr)
|
||||
if not is_day_allowed:
|
||||
verr = _('Not allowed, the resource is not available '
|
||||
'this day. Please choose another date.')
|
||||
'this day : {}. Please choose another '
|
||||
'date.'.format(reservation_day.strftime('%A')))
|
||||
raise ValidationError(verr)
|
||||
# Check if the resource is already taken during this period
|
||||
# PERF : check for res that can be in conflict,
|
||||
# do not iterate over all reservations
|
||||
domain = [('resource_id', '=', reservation.resource_id.id),
|
||||
('date_start', '<=', reservation.date_stop),
|
||||
('date_stop', '>=', reservation.date_start),
|
||||
('state', 'in', ('confirmed', 'validated')),
|
||||
('id', '!=', reservation.id)]
|
||||
reservations = self.env['golem.resource.reservation'].search(domain)
|
||||
|
Loading…
Reference in New Issue
Block a user