workflows/create_formdata: add tracking-code after formdata storage (#47649)

This commit is contained in:
Thomas NOËL 2020-10-13 23:28:07 +02:00
parent fd12d2bc4a
commit 9e837f2ffe
2 changed files with 6 additions and 4 deletions

View File

@ -4821,6 +4821,8 @@ def test_create_formdata(pub):
created_formdata = target_formdef.data_class().select()[0]
assert created_formdata.tracking_code is not None
assert pub.tracking_code_class.count() == 1
assert pub.tracking_code_class.select()[0].formdef_id == target_formdef.id
assert pub.tracking_code_class.select()[0].formdata_id == created_formdata.id
create.condition = {'type': 'python', 'value': '1 == 2'}
wf.store()

View File

@ -352,10 +352,6 @@ class CreateFormdataWorkflowStatusItem(WorkflowStatusItem):
self.apply_mappings(dest=new_formdata, src=formdata)
if formdef.enable_tracking_codes:
code = get_publisher().tracking_code_class()
code.formdata = new_formdata # this will .store() the code
if self.draft:
new_formdata.status = 'draft'
new_formdata.store()
@ -367,6 +363,10 @@ class CreateFormdataWorkflowStatusItem(WorkflowStatusItem):
new_formdata.perform_workflow()
new_formdata.store()
if formdef.enable_tracking_codes:
code = get_publisher().tracking_code_class()
code.formdata = new_formdata # this will .store() the code
if new_formdata.user_id is None and not new_formdata.backoffice_submission and get_session():
get_session().mark_anonymous_formdata(new_formdata)