Book Image

Odoo 11 Development Essentials - Third Edition

By : Daniel Reis
Book Image

Odoo 11 Development Essentials - Third Edition

By: Daniel Reis

Overview of this book

Odoo continues to gain worldwide momentum as the best platform for open source ERP installations. Now, with Odoo 11, you have access to an improved GUI, performance optimization, integrated in-app purchase features, and a fast-growing community to help transform and modernize your business. With this practical guide, you will cover all the new features that Odoo 11 has to offer to build and customize business applications, focusing on the publicly available community edition. We begin with setting up a development environment, and as you make your way through the chapters, you will learn to build feature-rich business applications. With the aim of jump-starting your Odoo proficiency level, from no specific knowledge to application development readiness, you will develop your first Odoo application. We then move on to topics such as models and views, and understand how to use server APIs to add business logic, helping to lay a solid foundation for advanced topics. The book concludes with Odoo interactions and how to use the Odoo API from other programs, all of which will enable you to efficiently integrate applications with other external systems.
Table of Contents (20 chapters)
Title Page
Packt Upsell
Contributors
Preface
Index

The business logic layer


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

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 decorator. Here, self will represent a recordset, and we should then loop through each record. In...