diff --git a/smash/web/forms.py b/smash/web/forms.py index 2294dd24246be9f0da6205e41a5cf3ad70e22317..80e00359544498c0bdcc726ca6e59067381e3958 100644 --- a/smash/web/forms.py +++ b/smash/web/forms.py @@ -88,7 +88,10 @@ def get_new_screening_number(screening_number_prefix): screening_number = screening_number.strip() if screening_number.startswith(screening_number_prefix): number = screening_number[len(screening_number_prefix):] - result_number = max(result_number, int(number)) + try: + result_number = max(result_number, int(number)) + except ValueError: + pass return screening_number_prefix + str(result_number + 1).zfill(3) diff --git a/smash/web/tests/test_SubjectAddForm.py b/smash/web/tests/test_SubjectAddForm.py index de00468a4beda5930c56592887c3a87f516b9b5a..158814504a49e84a5c26e84e8e837ad9c5aa92d4 100644 --- a/smash/web/tests/test_SubjectAddForm.py +++ b/smash/web/tests/test_SubjectAddForm.py @@ -135,3 +135,12 @@ class SubjectAddFormTests(TestCase): new_screening_number = get_new_screening_number(prefix) self.assertEqual(prefix + "201", new_screening_number) + + def test_get_new_screening_number_6(self): + prefix = "X-" + subject = create_subject() + subject.screening_number = "X-" + subject.save() + + new_screening_number = get_new_screening_number(prefix) + self.assertEqual(prefix + "001", new_screening_number)