diff --git a/smash/web/tests/view/test_kit_request.py b/smash/web/tests/view/test_kit_request.py index f0d199b6fff21bc039695c1caa1e30e53330062a..e1c4a1e79613dc93f1c6c682f59c50d91a56a48c 100644 --- a/smash/web/tests/view/test_kit_request.py +++ b/smash/web/tests/view/test_kit_request.py @@ -96,6 +96,29 @@ class ViewFunctionsTests(LoggedInTestCase): self.assertEqual(appointment1, result['appointments'][1]) self.assertEqual(appointment2, result['appointments'][2]) + def test_kit_requests_for_appointment_with_two_types(self): + item = Item.objects.create(disposable=True, name="item 1") + appointment_type = create_appointment_type() + appointment_type.required_equipment.add(item) + appointment_type.save() + + item = Item.objects.create(disposable=True, name="item 2") + appointment_type2 = create_appointment_type() + appointment_type2.required_equipment.add(item) + appointment_type2.save() + + visit = create_visit() + + appointment1 = create_appointment(visit) + appointment1.datetime_when = get_today_midnight_date() + datetime.timedelta(days=3) + appointment1.save() + AppointmentTypeLink.objects.create(appointment=appointment1, appointment_type=appointment_type) + AppointmentTypeLink.objects.create(appointment=appointment1, appointment_type=appointment_type2) + + result = get_kit_requests(self.user) + + self.assertEqual(1, len(result["appointments"])) + def test_kit_requests_send_email(self): item_name = "Test item to be ordered" item = Item.objects.create(disposable=True, name=item_name) diff --git a/smash/web/views/kit.py b/smash/web/views/kit.py index a20d266f11c98d59b7d1cf3aa82dcd75cf80652e..7c8875662f27ed77399d44984546684d94da1127 100644 --- a/smash/web/views/kit.py +++ b/smash/web/views/kit.py @@ -45,7 +45,7 @@ def get_kit_requests(user, start_date=None, end_date=None): datetime_when__gt=start_date, location__in=get_filter_locations(user), status=Appointment.APPOINTMENT_STATUS_SCHEDULED, - ).order_by('datetime_when') + ).distinct().order_by('datetime_when') if end_date is not None: appointments = appointments.filter(datetime_when__lt=end_date)