When building a website, URLs and routing play a crucial role in ensuring effective navigation and content delivery. URLs (Uniform Resource Locators) are the web addresses that users enter into their browsers to access specific pages or resources on a website. Routing, on the other hand, refers to the process of directing incoming requests to the appropriate pages or resources based on the URL.In the context of building a website, understanding URLs and routing involves creating a logical structure for organizing web pages and determining how users can access them. This includes defining URL patterns, establishing routes, and implementing appropriate handling mechanisms for different types of requests.
2. ● Controllers are used to configure the front end module.
Controllers are created by inheriting the controller.
● Routes are defined through methods decorated with
route()
Let’s check with an example.
We can bring all the sale order details to a webpage.
3. For that i have created a custom module named tips_and_tricks as follows:
4. In the directory controllers there are two python files, in “ __init__.py ” i have imported the
main.py and in “ main.py ” i have written a controller as shown below.
5. The http.Controller was inherited, Inside the route decorator i have specified the page URL as
“ /salesdata ”. Along with URL we can see some other parameters:
• type : It is used to specify the request type. It can be either http or json here i have used http.
• auth : it defines the access to the URL, possible values are user, public & none. here i’m using
public.
• website : It shows the controller either linked to the webpage or not, possible values are True
or False
6. • Inside the function definition i have searched for all sale order records
with the sales_data variable using search method.
• “ sudo() ” is used to get the super user access and inside the dictionary i
have passed the sales data like this.
• Now we can render the webpage with the sales data as shown in the
image. We are rendering the dictionary values along with the template.
7. • I have created a directory “ views “ with an xml file named as “ salesdata.xml “
and specified the absolute path in the module manifest file.
• In the sales data.xml i have created the template id as ” tmp_sales_data “ that
have already mentioned while rendering.
• Template consist of a basic odoo website layout and a div created with class
oe_structure and a inner div created with class container.
• A heading is added to the webpage as Sale Order Details.
8. After that we had created a table with class table-striped with thead and tbody as follows:
9.
10. • thead section contains all the table headings
• tbody section we are using foreach for looping the column values.
Here records have the all sale order details and every time order contains an
sale order object.
So that we can access all fields from the sale order by using dot.
11. Now is the time to test the functionality of the module.
For that install the module and go to website enter the URL ( salesdata )
mentioned in the controller as shown below.
12. Finally the result is here. We can see the all sale order details in this web page.
13. The “ __init__.py ” of the module contains the directory controllers were imported and
make the “__manifest__.py” as shown in below:
14. Check our company website
for related blogs and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.