diff --git a/crc/services/workflow_service.py b/crc/services/workflow_service.py index 6bfba31c..e6d4c56b 100755 --- a/crc/services/workflow_service.py +++ b/crc/services/workflow_service.py @@ -590,7 +590,9 @@ class WorkflowService(object): next_task = processor.next_task() if next_task: previous_form_data = WorkflowService.get_previously_submitted_data(processor.workflow_model.id, next_task) - DeepMerge.merge(next_task.data, previous_form_data) +# DeepMerge.merge(next_task.data, previous_form_data) + next_task.data = DeepMerge.merge(previous_form_data, next_task.data) + workflow_api.next_task = WorkflowService.spiff_task_to_api_task(next_task, add_docs_and_forms=True) # Update the state of the task to locked if the current user does not own the task. user_uids = WorkflowService.get_users_assigned_to_task(processor, next_task) diff --git a/tests/data/prefer_task_data_over_previous_form_submission/prefer_task_data_over_previous_form_submission.bpmn b/tests/data/prefer_task_data_over_previous_form_submission/prefer_task_data_over_previous_form_submission.bpmn new file mode 100644 index 00000000..1cda8836 --- /dev/null +++ b/tests/data/prefer_task_data_over_previous_form_submission/prefer_task_data_over_previous_form_submission.bpmn @@ -0,0 +1,68 @@ + + + + + Flow_14i1985 + + + + + + + + + + + + + + + + Flow_14i1985 + Flow_04lkxb1 + + + + the word {{word}} starts with the letter {{letter}} + Flow_13ka4e1 + + + + + + + + + Flow_04lkxb1 + Flow_13ka4e1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/workflow/test_workflow_previous_form_data.py b/tests/workflow/test_workflow_previous_form_data.py new file mode 100644 index 00000000..0b76a5dd --- /dev/null +++ b/tests/workflow/test_workflow_previous_form_data.py @@ -0,0 +1,35 @@ +import json +from tests.base_test import BaseTest + + +class TestFormFieldName(BaseTest): + + def test_prefer_task_data_over_previous_form_submission(self): + """It is nice to have the previous information show up when having to re-complete a form you filled + out previously. However, you don't want to overwrite something if it exists in the task-data already. + You can demonstrate this by setting the same value with two different forms. The second of the two + forms should always start with the data submitted by the first form. No mater how many times we submit and + go back. """ + + workflow = self.create_workflow('prefer_task_data_over_previous_form_submission') + + workflow_api = self.get_workflow_api(workflow) + task_1 = workflow_api.next_task + self.assertEquals('pick_letter', task_1.name) + workflow_api = self.complete_form(workflow, task_1, {'template':'a'}) + task_2 = workflow_api.next_task + self.assertEquals('complete_word', task_2.name) + self.assertEquals('a', task_2.data['template']) + workflow_api = self.complete_form(workflow, task_2, {'template':'a'}) + + self.restart_workflow_api(workflow_api, clear_data=False) + workflow_api = self.get_workflow_api(workflow) + task_1 = workflow_api.next_task + self.assertEquals('pick_letter', task_1.name) + workflow_api = self.complete_form(workflow, task_1, {'template':'b'}) + task_2 = workflow_api.next_task + self.assertEquals('complete_word', task_2.name) + # HERE is the real test, if we use the task data, then template is set to "b", but if we + # overwrite the task_data with the last form submission, it ends up being "a". If + # the value is already set in task_data, it should not be overwitten. + self.assertEquals('b', task_2.data['template'])