Skip to content

Commit

Permalink
Fix queryset existence check for bed validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Ashesh3 committed Jul 9, 2022
1 parent c0d27cf commit aa77f60
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,10 @@ def validate(self, attrs):
existing_qs = ConsultationBed.objects.filter(
consultation=consultation, bed=bed
)
latest_qs = ConsultationBed.objects.filter(
consultation=consultation
).latest("id")
qs = ConsultationBed.objects.filter(consultation=consultation)
# Validations based of the latest entry
if latest_qs.exists():
if qs.exists():
latest_qs = qs.latest("id")
if latest_qs.bed == bed:
raise ValidationError({"bed": "Bed is already in use"})
if start_date < latest_qs.start_date:
Expand Down

0 comments on commit aa77f60

Please sign in to comment.