Using Odoo to create websites and web services

In previous examples, we have been extending the Odoo framework to include additional fields in models and functionality in our views. Odoo also provides a powerful framework for creating your own websites and web services that can integrate easily with Odoo applications.

Let's see how we can create a simple web service that displays rush orders on a page.

We begin by creating a controller that is tied to a URL. When we navigate to this URL in our browser, the controller will do whatever processing we require.

Create the controller file using the following command in your Terminal window:

sudo nano controller.py

Add in the following code to create a simple output so we can test our controller and make sure it is functioning properly. Place this code in the controller.py file:

from odoo import http 
 
class Web_RushOrders(http.Controller): 
    @http.route('/orders/rush/', auth='public') 
    def index(self, **kw): 
        return "Rush Orders"

You must now edit the __init__.py file to include the new controller file:

You can edit the __init__.py file by using the following command:
sudo nano __init__.py.

This allows the controller.py file we have created to get picked up by the Odoo framework.

Now start and stop the Odoo server and navigate to http://localhost:8069/orders/rush.

You will then see the custom web page displayed as follows:

Now that we have tested our controller and have a very simple page, let's see how we can hook into the Odoo sales application and display our rush orders.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.148.105