Skip to Content
Menu
This question has been flagged
1 Reply
3079 Views

Hello,


in a customized report, i have added a data table to present tasks in the report but i need some tasks to be presented in the report, how do I filter and sort the table?


Thank you,

Avatar
Discard

Have you succeeded in bring all the tasks record into the record, if yes before do that you can try use filtered() method or sorted() method

Best Answer

Hi,

In your custom Odoo report, if you have successfully included all the task records, you can further refine the displayed data by applying filters and sorting directly in the report logic. Here are detailed examples:

1. Apply Domain Filtering:


 if you only want to include tasks that are in progress and belong to a specific project, you can specify this in the domain.

domain = [

    ('state', '=', 'in_progress'),

    ('project_id', '=', specific_project_id)

]

tasks = self.env['project.task'].search(domain)

2. Use .filtered() Operation.

filtered_task = tasks.filtered(lambda t: t.name == any_name)

Apply additional filtering to include tasks with a specific name for example. This method allows for more complex filtering that doesn't directly translate into a domain


3. Sorting Tasks Using .sorted()


sorted_tasks = filtered_tasks.sorted(key=lambda t: t.created_date)

The .sorted() method sorts these tasks, enabling you to display them in a logical order in the report.


Hope it helps

Avatar
Discard
Related Posts Replies Views Activity
2
Sep 24
2104
5
Aug 19
46698
4
Jun 18
20275
0
Jun 18
3435
2
May 16
17259