With Athento it is possible to filter the trays by type of task, for this, you must use a mask that modifies the behaviour of the tray.
In this case, it is necessary to use a mask to filter by task type. Only the documents that have a task of the filtered type and that this task is in ‘open’ status will be shown in the tray.
Mask code
To create a mask that filters by task type, the following code can be used as a starting point:
import time
import datetime
import json
def run(q, items, **kwargs):
from users.utils import UsersUtils
other_data = {}
new_items = []
params = q.mask_params
params = json.loads(params)
tareas = params.get('tareas', '')
task_names = tareas.split(',')
for i in items:
doc = i.get('doc')
tasks = doc.get_workflow_tasks()
tasks = tasks.filter(status='Open', removed=False)
if tasks:
for task in tasks:
task_name = task.task_type.name
task_name = str(task_name)
if task_name in task_names:
new_doc = i.copy()
new_items.append(new_doc)
new_doc['task_name'] = task.task_type.name
return new_items
This code can be modified to add further filters or conditions as required.
Installation
The masks must be added to the custom repository in the ‘queuemasks’ folder and be Python code files.
After adding them to the repository, the instance needs to be updated (which updates the custom code). This update can be requested to technical support or can be done from the instance itself, if the feature is enabled in the update centre.
Once the instance has been updated, the ‘Mask method’ field must be configured from the advanced tray, replacing in custom.
<repository_name>.queuemasks.<mask_name> the repository_name and the mask_name:
Finally, to choose which task types to display, a JSON in the ‘Masks params’ field must be added in the following format:
Where the key is ‘tasks’ and in the value the names of the task types separated by comma are added. These names are obtained from the advanced document workflow task types, copying the name of the task:
With the changes made, the tray will now show only documents with open tasks of the selected types.
Filter by tasks assigned to the current user
You can also add a filter so that only documents with open tasks assigned to the current user (the one consulting the tray) are shown. To do this, the code must be modified by adding what is in bold and commenting out the line that gets the tasks from the document.
import time
import datetime
import json
def run(q, items, **kwargs):
from django_currentuser.middleware import get_current_user
from users.utils import UsersUtils
current_user = UsersUtils.get_current_user()
other_data = {}
new_items = []
params = q.mask_params
params = json.loads(params)
tareas = params.get('tareas', '')
task_names = tareas.split(',')
for i in items:
doc = i.get('doc')
#tasks = doc.get_workflow_tasks()
tasks = current_user.get_workflow_tasks(doc)
tasks = tasks.filter(status='Open', removed=False)
if tasks:
for task in tasks:
task_name = task.task_type.name
task_name = str(task_name)
if task_name in task_names:
new_doc = i.copy()
new_items.append(new_doc)
new_doc['task_name'] = task.task_type.name
return new_items
Comments
0 comments
Please sign in to leave a comment.