Book Image

Odoo 10 Development Essentials

By : Daniel Reis
Book Image

Odoo 10 Development Essentials

By: Daniel Reis

Overview of this book

Odoo is one of the fastest growing open source, business application development software products available. With announcement of Odoo 10, there are many new features added to Odoo and the face of business applications developed with Odoo has changed. This book will not only teach you how to build and customize business applications with Odoo, but it also covers all the new features that Odoo has to offer. This book is the latest resource on developing and customizing Odoo 10 applications. It comes packed with much more and refined content than its predecessor. It will start with building business applications from scratch and will cover topics such as module extensions, inheritance, working with data, user interfaces, and so on. The book also covers the latest features of Odoo 10, in addition to front end development, testing and debugging techniques. The book will also talk about Odoo Community and Odoo Enterprise.
Table of Contents (20 chapters)
Odoo 10 Development Essentials
Credits
Foreword
About the Author
About the Reviewer
www.PacktPub.com
Preface

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 True 

The code loops through all the to-do task records and, for each one, modifies the is_done field, inverting its value. The method does not need to return anything, but we should have it to...