Book Image

Odoo Development Cookbook

By : Holger Brunn, Alexandre Fayolle, Daniel Reis
Book Image

Odoo Development Cookbook

By: Holger Brunn, Alexandre Fayolle, Daniel Reis

Overview of this book

Odoo is a full-featured open source ERP with a focus on extensibility. The flexibility and sustainability of open source is also a key selling point of Odoo. It is built on a powerful framework for rapid application development, both for back-end applications and front-end websites. The book starts by covering Odoo installation and administration, and provides a gentle introduction to application development. It then dives deep into several of the areas that an experienced developer will need to use. You’ll learn implement business logic, adapt the UI, and extend existing features.
Table of Contents (23 chapters)
Odoo Development Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Using client-side QWeb templates


Just as it's a bad pattern to programmatically create HTML code in controllers, you should create only the minimum amount of DOM elements in your client side JavaScript code. Fortunately, there's a templating engine available for the client side too and, even more fortunately, it's just the same as for server side code.

We'll use Qweb to make the module from the previous recipe, Create custom widgets, more modular by moving the DOM element creation to QWeb.

Getting ready

This recipe is just a modified version of the previous recipe, Create custom widgets, code, so grab a copy of it and use it to create the module ch15_r02.

How to do it...

We add the QWeb definition in the manifest and change the JavaScript code to use it:

  1. Remove the entire function start from your JavaScript code in static/src/js/ch15_r02.js, but add a member called template:

        var FieldMany2OneButtons = form_common.AbstractField.extend({
            template: 'FieldMany2OneButtons',
  2. Add the template...