Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: Aakash Singh <[email protected]>
  • Loading branch information
sainak committed Aug 18, 2023
1 parent 5383974 commit a76402a
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions care/facility/api/serializers/bed.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,18 @@ def validate(self, attrs):
raise ValidationError(
{"bed": "Bed is already in use by another patient"}
)
previous_consultation_bed = consultation.current_bed

if consultation.current_bed.bed == bed and set(
consultation.current_bed.assets.order_by("external_id").values_list(
"external_id", flat=True
if (
previous_consultation_bed
and previous_consultation_bed.bed == bed
and set(
previous_consultation_bed.assets.order_by(
"external_id"
).values_list("external_id", flat=True)
)
) == set(attrs.get("assets", [])):
== set(attrs.get("assets", []))
):
raise ValidationError(
{"consultation": "These set of bed and assets are already assigned"}
)
Expand Down Expand Up @@ -257,8 +263,8 @@ def create(self, validated_data):
]
)

consultation.current_bed = obj
consultation.save(update_fields=["current_bed"])
consultation.current_bed = obj
consultation.save(update_fields=["current_bed"])
return obj

def update(self, instance: ConsultationBed, validated_data) -> ConsultationBed:
Expand Down

0 comments on commit a76402a

Please sign in to comment.