The business logic layer

Now we will add some logic to our buttons. This is done with Python code, using the methods in the model's Python class.

Adding business logic

We should edit the todo_model.py Python file to add to the class the methods called by the buttons. 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 models, fields, api 

The action of the Toggle Done button will be very simple: just toggle the Is Done? flag. For logic on records, use the @api.multi decorator. Here, self will represent a recordset, and we should then loop through each record.

Inside the TodoTask class, add this:

@api.multi def do_toggle_done(self): for task in self: task.is_done = not task.is_done return ...

Get Odoo 10 Development Essentials 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.