Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
3572 Prikazi

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
Opusti

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
Opusti
Related Posts Odgovori Prikazi Aktivnost
2
sep. 24
2728
5
avg. 19
47224
4
jun. 18
20881
0
jun. 18
3854
2
maj 16
17934