November 2016
Beginner to intermediate
298 pages
6h 10m
English
Now we will add some logic to our buttons. This is done with Python code, using the methods in the model's Python class.
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 ...
Read now
Unlock full access