Adding business logic

We should edit the todo_task_model.py Python file to add the methods called by the button. First, we need to import the new API, so add it to the import statement at the top of the Python file:

from odoo import api, fields, models 

The logic for the Clear Done button is quite simple: just set the Active? flag to false. This takes advantage of an ORM built-in feature: records with an active flag set to False by default are filtered out and won't be presented to the user. You can think of it as a "soft delete."

In the models/todo_task_model.py file, add the following to the TodoTask class:

@api.multi 
def do_clear_done(self): 
    for task in self: 
        task.active = False 
    return True 

For logic on records, we use the @api.multi ...

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.