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

Make a path accessible from the network


In this recipe, we'll see how to make a URL of the form http://yourserver/path1/path2 accessible to users. This can either be a web page or a path returning arbitrary data to be consumed by other programs. In the latter case, you would usually use the JSON format to consume parameters and to offer your data.

Getting ready

We'll make use of the library.book model of Chapter 4, Application Models, so in case you haven't done so yet, grab its code to be able to follow the examples.

We want to allow any user to query the full list of books. Furthermore, we want to provide the same information to programs via a JSON request.

How to do it…

We'll need to add controllers, which go into a folder called controllers by convention:

  1. Add a controllers/main.py file with the HTML version of our page:

    from openerp import http
    from openerp.http import request
    
    class Main(http.Controller):
        @http.route('/my_module/books', type='http', auth='none')
        def books(self):
     ...