Skip to content

Commit

Permalink
change overlapping check
Browse files Browse the repository at this point in the history
  • Loading branch information
RignonNoel committed Sep 14, 2020
1 parent ee1ae29 commit 9f31e31
Showing 1 changed file with 32 additions and 18 deletions.
50 changes: 32 additions & 18 deletions retirement/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,15 +385,22 @@ def validate(self, attrs):
active_reservations = active_reservations.all()

for reservation in active_reservations:
latest_start = max(reservation.retreat.start_time, start)
shortest_end = min(reservation.retreat.end_time, end)
if latest_start < shortest_end:
raise serializers.ValidationError({
'non_field_errors': [_(
"This reservation overlaps with another active "
"reservations for this user."
)]
})
for date in reservation.retreat.retreat_dates:
latest_start = max(
date.start_time,
start,
)
shortest_end = min(
date.end_time,
end,
)
if latest_start < shortest_end:
raise serializers.ValidationError({
'non_field_errors': [_(
"This reservation overlaps with another active "
"reservations for this user."
)]
})
return attrs

def create(self, validated_data):
Expand Down Expand Up @@ -585,15 +592,22 @@ def update(self, instance, validated_data):
).exclude(pk=instance.pk)

for reservation in active_reservations:
latest_start = max(reservation.retreat.start_time, start)
shortest_end = min(reservation.retreat.end_time, end)
if latest_start < shortest_end:
raise serializers.ValidationError({
'non_field_errors': [_(
"This reservation overlaps with another "
"active reservations for this user."
)]
})
for date in reservation.retreat.retreat_dates:
latest_start = max(
date.start_time,
start,
)
shortest_end = min(
date.end_time,
end,
)
if latest_start < shortest_end:
raise serializers.ValidationError({
'non_field_errors': [_(
"This reservation overlaps with another "
"active reservations for this user."
)]
})
if need_transaction:
order = Order.objects.create(
user=user,
Expand Down

0 comments on commit 9f31e31

Please sign in to comment.