workflows: add a tracking-code on created formdata (#46250)
This commit is contained in:
parent
8b70e64f84
commit
04a6ca00ba
|
@ -4657,6 +4657,7 @@ def test_aggregation_email(pub, emails):
|
|||
def test_create_formdata(pub):
|
||||
FormDef.wipe()
|
||||
LoggedError.wipe()
|
||||
pub.tracking_code_class.wipe()
|
||||
|
||||
target_formdef = FormDef()
|
||||
target_formdef.name = 'target form'
|
||||
|
@ -4707,6 +4708,21 @@ def test_create_formdata(pub):
|
|||
assert any('form_var_toto_string' in (error.exception_message or '') for error in errors)
|
||||
assert any('Missing field' in error.summary for error in errors)
|
||||
|
||||
# no tracking code has been created
|
||||
created_formdata = target_formdef.data_class().select()[0]
|
||||
assert created_formdata.tracking_code is None
|
||||
assert pub.tracking_code_class.count() == 0
|
||||
# now we want one
|
||||
target_formdef.enable_tracking_codes = True
|
||||
target_formdef.store()
|
||||
target_formdef.data_class().wipe()
|
||||
formdata.perform_workflow()
|
||||
# and a tracking code is created
|
||||
assert target_formdef.data_class().count() == 1
|
||||
created_formdata = target_formdef.data_class().select()[0]
|
||||
assert created_formdata.tracking_code is not None
|
||||
assert pub.tracking_code_class.count() == 1
|
||||
|
||||
create.condition = {'type': 'python', 'value': '1 == 2'}
|
||||
wf.store()
|
||||
del source_formdef._workflow
|
||||
|
|
|
@ -342,6 +342,10 @@ 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()
|
||||
|
|
Loading…
Reference in New Issue