diff --git a/caluma/caluma_form/domain_logic.py b/caluma/caluma_form/domain_logic.py index 15c0dc1e1..98940b746 100644 --- a/caluma/caluma_form/domain_logic.py +++ b/caluma/caluma_form/domain_logic.py @@ -121,24 +121,9 @@ def _set_default_answers_for_form(form, document): question.sub_form, document ) continue - new_answer = question.default_answer.copy(document_family=document.family) - if question.type == models.Question.TYPE_TABLE: - # In case of table questions, we have to evaluate what default to use. - # The default value in a row_document wins over the default_answer of a - # row_form question - for row_doc in new_answer.documents.iterator(): - row_doc_answers = [] - for sub_question in question.row_form.questions.filter( - default_answer__isnull=False - ).iterator(): - if not row_doc.answers.filter(question=sub_question).exists(): - row_doc_answers.append( - sub_question.default_answer.copy( - document_family=document.family - ) - ) - row_doc.answers.add(*row_doc_answers) - answers.append(new_answer) + answers.append( + question.default_answer.copy(document_family=document.family) + ) document.answers.add(*answers) return document diff --git a/caluma/caluma_form/tests/test_document.py b/caluma/caluma_form/tests/test_document.py index 4e5623fba..30dfa292a 100644 --- a/caluma/caluma_form/tests/test_document.py +++ b/caluma/caluma_form/tests/test_document.py @@ -999,9 +999,9 @@ def test_save_document_table_answer_setting_family( assert to_be_deleted_table_row.family == to_be_deleted_document.family -@pytest.mark.parametrize("default_on_table,value", [(True, 1979), (False, 23)]) +@pytest.mark.parametrize("default_on_table", [True, False]) def test_save_document_table_answer_default_answer( - db, form_and_document, answer_factory, default_on_table, value + db, form_and_document, answer_factory, default_on_table ): form, document, questions_dict, answers_dict = form_and_document(use_table=True) @@ -1027,7 +1027,10 @@ def test_save_document_table_answer_default_answer( assert Document.objects.filter(form=form).count() == 2 assert doc.answers.count() == 1 - assert doc.answers.first().documents.first().answers.first().value == value + if default_on_table: + assert doc.answers.first().documents.first().answers.first().value == 1979 + else: + assert doc.answers.first().documents.first().answers.first() is None @pytest.mark.parametrize("answer__value", [1.1])