misc: check condition in mass jumps (#73259) #25
|
@ -760,6 +760,68 @@ def test_backoffice_multi_actions_jump(pub):
|
|||
assert formdef.data_class().get(id).status == 'wf-accepted'
|
||||
|
||||
|
||||
def test_backoffice_multi_actions_jump_condition(pub):
|
||||
create_superuser(pub)
|
||||
FormDef.wipe()
|
||||
lguerin marked this conversation as resolved
Outdated
|
||||
Workflow.wipe()
|
||||
|
||||
workflow = Workflow.get_default_workflow()
|
||||
workflow.id = '2'
|
||||
# add identifier to jumps
|
||||
accept_button = workflow.get_status('new').items[1]
|
||||
accept_button.identifier = 'accept'
|
||||
workflow.get_status('new').items[2].identifier = 'reject'
|
||||
workflow.store()
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.fields = []
|
||||
formdef.workflow_roles = {'_receiver': 1}
|
||||
formdef.workflow_id = workflow.id
|
||||
formdef.store()
|
||||
|
||||
for i in range(10):
|
||||
formdata = formdef.data_class()()
|
||||
formdata.just_created()
|
||||
if i % 3 == 0:
|
||||
formdata.jump_status('finished')
|
||||
else:
|
||||
formdata.jump_status('new')
|
||||
formdata.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/management/form-title/')
|
||||
resp.forms['listing-settings']['filter'] = 'new'
|
||||
resp.forms['listing-settings']['filter-operator'] = 'eq'
|
||||
resp = resp.forms['listing-settings'].submit()
|
||||
assert 'select[]' in resp.forms['multi-actions'].fields
|
||||
assert len(resp.pyquery.find('#multi-actions div.buttons button')) == 2
|
||||
|
||||
checked_ids = []
|
||||
for checkbox in resp.forms[0].fields['select[]'][1:6]:
|
||||
checked_ids.append(checkbox._value)
|
||||
checkbox.checked = True
|
||||
|
||||
# modify jump to have a condition so it's not executed on some of the checked formdatas
|
||||
selected_ids = [checked_ids[1], checked_ids[2]]
|
||||
accept_button.condition = {
|
||||
'type': 'django',
|
||||
'value': 'form_number_raw == "%s" or form_number_raw == "%s"' % tuple(selected_ids),
|
||||
}
|
||||
workflow.store()
|
||||
|
||||
resp = resp.forms['multi-actions'].submit('button-action-st-accept')
|
||||
assert '?job=' in resp.location
|
||||
resp = resp.follow()
|
||||
assert 'Executing task "Accept" on forms' in resp.text
|
||||
assert '>completed<' in resp.text
|
||||
for id in checked_ids:
|
||||
if id in selected_ids:
|
||||
assert formdef.data_class().get(id).status == 'wf-accepted'
|
||||
else:
|
||||
assert formdef.data_class().get(id).status == 'wf-new'
|
||||
|
||||
|
||||
def test_backoffice_multi_actions_oldest_form(pub):
|
||||
create_superuser(pub)
|
||||
create_environment(pub)
|
||||
|
|
|
@ -4213,10 +4213,11 @@ class MassActionAfterJob(AfterJob):
|
|||
)
|
||||
if getattr(action['action'], 'status_action', False):
|
||||
# manual jump action
|
||||
from wcs.wf.jump import jump_and_perform
|
||||
if action['action'].action.check_condition(formdata):
|
||||
from wcs.wf.jump import jump_and_perform
|
||||
|
||||
formdata.record_workflow_event('mass-jump', action_item_id=action['action'].action.id)
|
||||
jump_and_perform(formdata, action['action'].action)
|
||||
formdata.record_workflow_event('mass-jump', action_item_id=action['action'].action.id)
|
||||
jump_and_perform(formdata, action['action'].action)
|
||||
else:
|
||||
# global action
|
||||
formdata.record_workflow_event('global-action-mass', global_action_id=action['action'].id)
|
||||
|
|
Loading…
Reference in New Issue
ça crée vraiment beaucoup de donnée (et ça ralentit les tests), possible de faire sans ?