Smart buttons

When designing the form structure, we included a top-right area to contain smart buttons.  Let's now add a button inside it.

For our app, we will have a button displaying the total number of To-Do tasks for the owner of the current To-Do task, and clicking on it will navigate to the list of those items.

First, we need to add the corresponding computed field to models/todo_task_model.py. Add the following to the TodoTask class:

def _compute_user_todo_count(self):
    for task in self:
        task.user_todo_count = task.search_count(
            [('user_id', '=', task.user_id.id)]) 

user_todo_count = fields.Integer(
    'User To-Do Count',
    compute='_compute_user_todo_count')

Next, we add the button box and the button inside it. Right at the top of the

Get Odoo 11 Development Essentials - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.