際際滷

際際滷Share a Scribd company logo
5
Most read
7
Most read
8
Most read
URLs & Routing in
Odoo 17 Website App
Enterprise
Introduction
Enterprise
In Odoo, Controllers are used to configure front-end modules
under Website. Using controllers, we can specify the URL to the
link the web pages.
For that, we need to setup the controller in our module and
create an xml template to load the data in the web page.
Enterprise
Here, as an example just create a module named sale_detail
as follows.
Enterprise
Step 1: Create a Controller in the custom module
 In the directory Controllers inside the module, there are
two python files (here its is main.py) and __init__.py.
main.py have the method with which the data is taken
from backend module to show in the website.
Enterprise
 Inside main.py, import the http and http.request and create
a class to write the method. Then, use the method decorator
@http.route to navigate to a specific page using controller
from odoo import http
from odoo.http import request
class SaleDetail(http.Controller):
@http.route('/sale_detail',type='http', auth="public",
website=True)
def sale_detail(self, **arg):
Sale_detail = request.env['sale.order'].sudo().search([])
values = {'record' : sale_detail}
return request.render('sale_detail.all_sales_data', values)
Enterprise
 For the decorator, the first parameter /sale_details is the URL.
 The second parameter says the type of the request. It can be http or
json. Keep it as http. json requests are used to execute methods on
server to obtain result.
Type = 'http' is for responding over http request. It will take you to
the another template with the values with the dictionary passed and
will refresh the page
 Third parameter gives the authentication. The values can be public,
user or none.
 The last parameter website=True to make it visible on website
 Inside the method, fetch the data we need using sudo() to get data
as a super user. Here the sale order details are taken and set as a
value dictionary(values here)
 Render the template and pass the value dictionary by calling the
template with the syntax
module_name. template_name
Enterprise
Step 2: Create the Template
 Inside the directory views, create a new xml file to design
the template to display the data taken from backend
modules.
 Inside <odoo> tag, give a unique name for the template.
Keep in mind that the template name must be the same
when we render the template from the .py file.
<template id="sale_detail.all_sales_data"
name="Sales Details">
 Design the template by keeping Odoos default websites
layout using.
<t t-call="website.layout">
Enterprise
 Design the content using the <table>, <thead>, <tbody> tags.
Here, inside the div of class container, we have set a
heading for the data to be shown added a table with table-
striped class as
<br/>
<center>
<h2>SALE DETAILS</h2>
</center>
<table class="table-striped table">
<thead>
<th>Sale Order</th>
<th>Sale Customer</th>
<th>Date</th>
<th>Amount</th>
</thead>
Enterprise
 To iterate through multiple records, <t t-foreach> can be
used. Here in this example, inside <tbody>, to get the details
Sale order Number, Customer name, Date and Amount of
each Sale order, iterate as
<tbody>
<t t-foreach="record" t-as="so">
<tr>
<td><span t-esc="so.name"/></td>
<td><span t-esc="so.partner_id.name"/></td>
<td><span t-esc="so.date_order"/></td>
<td><span t-esc="so.amount_total"/></td>
</tr>
</t>
</tbody>
Enterprise
Step 3: Open the URL from the website
 Go to the website from UI and copy our URL used in the
controller, ie /sale_details here. The page will be loaded as
below with all the details we specified using the template.
For More Info.
Check our company website for related
blogs and Odoo book.
Check our YouTube channel for
functional and technical videos in Odoo.
Enterprise
www.cybrosys.com

More Related Content

Similar to URLs and Routing in the Odoo 17 Website App (20)

PPTX
URLS and routing in odoo 18 - Odoo 際際滷s
Celine George
PPTX
Building A Website - URLs and routing
RahulRaj965986
PPTX
How to Modify Existing Web Pages in Odoo 18
Celine George
PPTX
How to Create & Manage a Dashboard Using OWL in Odoo 17
Celine George
PPTX
How to add menu in Odoo 17 Website - Odoo 17 際際滷s
Celine George
PPTX
How to Store Data on the Odoo 17 Website
Celine George
PPTX
Odoo Building a website _ For the browser
Celine George
PPTX
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
PPTX
How to Add Pagination in Website portal in Odoo
Celine George
PPTX
Report Actions In Odoo 17 - Odoo 17 際際滷s
Celine George
PPTX
How to Create a Dynamic Report in Odoo 17
Celine George
PPTX
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
PPTX
How to Sell Your Products in Odoo 17 Website
Celine George
PDF
Step-by-Step Guide to Customizing Odoo Modules
Shiv Technolabs Pvt. Ltd.
PDF
A Comprehensive Guide to Customizing Key Modules in Odoo ERP
Shiv Technolabs Pvt. Ltd.
PPTX
Customization of Odoo 17 Periodic Digest parameters from backend
Celine George
PPTX
Odoo 13 inventory using routes (procurement, &amp; push rules)
PlanetOdoo
PPTX
Onchange
Celine George
PPTX
How to Load Custom Field to POS in Odoo 17 - Odoo 17 際際滷s
Celine George
PDF
Odoo eCommerce Features
Celine George
URLS and routing in odoo 18 - Odoo 際際滷s
Celine George
Building A Website - URLs and routing
RahulRaj965986
How to Modify Existing Web Pages in Odoo 18
Celine George
How to Create & Manage a Dashboard Using OWL in Odoo 17
Celine George
How to add menu in Odoo 17 Website - Odoo 17 際際滷s
Celine George
How to Store Data on the Odoo 17 Website
Celine George
Odoo Building a website _ For the browser
Celine George
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
How to Add Pagination in Website portal in Odoo
Celine George
Report Actions In Odoo 17 - Odoo 17 際際滷s
Celine George
How to Create a Dynamic Report in Odoo 17
Celine George
Tips On Trick Odoo Add-On.pptx
Agusto Sipahutar
How to Sell Your Products in Odoo 17 Website
Celine George
Step-by-Step Guide to Customizing Odoo Modules
Shiv Technolabs Pvt. Ltd.
A Comprehensive Guide to Customizing Key Modules in Odoo ERP
Shiv Technolabs Pvt. Ltd.
Customization of Odoo 17 Periodic Digest parameters from backend
Celine George
Odoo 13 inventory using routes (procurement, &amp; push rules)
PlanetOdoo
Onchange
Celine George
How to Load Custom Field to POS in Odoo 17 - Odoo 17 際際滷s
Celine George
Odoo eCommerce Features
Celine George

More from Celine George (20)

PPTX
How to Manage Expiry Date in Odoo 18 Inventory
Celine George
PPTX
Different types of inheritance in odoo 18
Celine George
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
PPTX
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
PPTX
How to use _name_search() method in Odoo 18
Celine George
PPTX
How to use grouped() method in Odoo 18 - Odoo 際際滷s
Celine George
PPTX
How to use ensure_one() method in Odoo 18
Celine George
PPTX
How to Add New Item in CogMenu in Odoo 18
Celine George
PPTX
How to use search fetch method in Odoo 18
Celine George
PPTX
List View Components in Odoo 18 - Odoo 際際滷s
Celine George
PPTX
How payment terms are configured in Odoo 18
Celine George
PPTX
How to Customize Quotation Layouts in Odoo 18
Celine George
PPTX
Code Profiling in Odoo 18 - Odoo 18 際際滷s
Celine George
PPTX
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
PPTX
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
PPTX
How to Manage Inventory Movement in Odoo 18 POS
Celine George
How to Manage Expiry Date in Odoo 18 Inventory
Celine George
Different types of inheritance in odoo 18
Celine George
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
How to Configure Refusal of Applicants in Odoo 18 Recruitment
Celine George
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
How to use _name_search() method in Odoo 18
Celine George
How to use grouped() method in Odoo 18 - Odoo 際際滷s
Celine George
How to use ensure_one() method in Odoo 18
Celine George
How to Add New Item in CogMenu in Odoo 18
Celine George
How to use search fetch method in Odoo 18
Celine George
List View Components in Odoo 18 - Odoo 際際滷s
Celine George
How payment terms are configured in Odoo 18
Celine George
How to Customize Quotation Layouts in Odoo 18
Celine George
Code Profiling in Odoo 18 - Odoo 18 際際滷s
Celine George
How to Manage Different Customer Addresses in Odoo 18 Accounting
Celine George
How to Implement Least Package Removal Strategy in Odoo 18 Inventory
Celine George
How to Manage Inventory Movement in Odoo 18 POS
Celine George
Ad

Recently uploaded (20)

PPTX
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
PDF
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
PDF
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
PDF
Romanticism in Love and Sacrifice An Analysis of Oscar Wildes The Nightingal...
KaryanaTantri21
PDF
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
PPTX
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
PPTX
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
PPTX
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
PPTX
Photo chemistry Power Point Presentation
mprpgcwa2024
PPTX
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
PDF
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
PDF
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
DOCX
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
PPTX
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
PPTX
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
PDF
COM and NET Component Services 1st Edition Juval L旦wy
kboqcyuw976
PDF
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
PPTX
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
JSON, XML and Data Science introduction.pptx
Ramakrishna Reddy Bijjam
CAD25 Gbadago and Fafa Presentation Revised-Aston Business School, UK.pdf
Kweku Zurek
Learning Styles Inventory for Senior High School Students
Thelma Villaflores
Romanticism in Love and Sacrifice An Analysis of Oscar Wildes The Nightingal...
KaryanaTantri21
Lesson 1 : Science and the Art of Geography Ecosystem
marvinnbustamante1
How Physics Enhances Our Quality of Life.pptx
AngeliqueTolentinoDe
F-BLOCK ELEMENTS POWER POINT PRESENTATIONS
mprpgcwa2024
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
Photo chemistry Power Point Presentation
mprpgcwa2024
ENGLISH -PPT- Week1 Quarter1 -day-1.pptx
garcialhavz
Andreas Schleicher_Teaching Compass_Education 2040.pdf
EduSkills OECD
Rapid Mathematics Assessment Score sheet for all Grade levels
DessaCletSantos
ANNOTATION on objective 10 on pmes 2022-2025
joviejanesegundo1
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
Elo the HeroTHIS IS A STORY ABOUT A BOY WHO SAVED A LITTLE GOAT .pptx
JoyIPanos
SYMPATHOMIMETICS[ADRENERGIC AGONISTS] pptx
saip95568
COM and NET Component Services 1st Edition Juval L旦wy
kboqcyuw976
Gladiolous Cultivation practices by AKL.pdf
kushallamichhame
Tanja Vujicic - PISA for Schools contact Info
EduSkills OECD
Ad

URLs and Routing in the Odoo 17 Website App

  • 1. URLs & Routing in Odoo 17 Website App Enterprise
  • 2. Introduction Enterprise In Odoo, Controllers are used to configure front-end modules under Website. Using controllers, we can specify the URL to the link the web pages. For that, we need to setup the controller in our module and create an xml template to load the data in the web page.
  • 3. Enterprise Here, as an example just create a module named sale_detail as follows.
  • 4. Enterprise Step 1: Create a Controller in the custom module In the directory Controllers inside the module, there are two python files (here its is main.py) and __init__.py. main.py have the method with which the data is taken from backend module to show in the website.
  • 5. Enterprise Inside main.py, import the http and http.request and create a class to write the method. Then, use the method decorator @http.route to navigate to a specific page using controller from odoo import http from odoo.http import request class SaleDetail(http.Controller): @http.route('/sale_detail',type='http', auth="public", website=True) def sale_detail(self, **arg): Sale_detail = request.env['sale.order'].sudo().search([]) values = {'record' : sale_detail} return request.render('sale_detail.all_sales_data', values)
  • 6. Enterprise For the decorator, the first parameter /sale_details is the URL. The second parameter says the type of the request. It can be http or json. Keep it as http. json requests are used to execute methods on server to obtain result. Type = 'http' is for responding over http request. It will take you to the another template with the values with the dictionary passed and will refresh the page Third parameter gives the authentication. The values can be public, user or none. The last parameter website=True to make it visible on website Inside the method, fetch the data we need using sudo() to get data as a super user. Here the sale order details are taken and set as a value dictionary(values here) Render the template and pass the value dictionary by calling the template with the syntax module_name. template_name
  • 7. Enterprise Step 2: Create the Template Inside the directory views, create a new xml file to design the template to display the data taken from backend modules. Inside <odoo> tag, give a unique name for the template. Keep in mind that the template name must be the same when we render the template from the .py file. <template id="sale_detail.all_sales_data" name="Sales Details"> Design the template by keeping Odoos default websites layout using. <t t-call="website.layout">
  • 8. Enterprise Design the content using the <table>, <thead>, <tbody> tags. Here, inside the div of class container, we have set a heading for the data to be shown added a table with table- striped class as <br/> <center> <h2>SALE DETAILS</h2> </center> <table class="table-striped table"> <thead> <th>Sale Order</th> <th>Sale Customer</th> <th>Date</th> <th>Amount</th> </thead>
  • 9. Enterprise To iterate through multiple records, <t t-foreach> can be used. Here in this example, inside <tbody>, to get the details Sale order Number, Customer name, Date and Amount of each Sale order, iterate as <tbody> <t t-foreach="record" t-as="so"> <tr> <td><span t-esc="so.name"/></td> <td><span t-esc="so.partner_id.name"/></td> <td><span t-esc="so.date_order"/></td> <td><span t-esc="so.amount_total"/></td> </tr> </t> </tbody>
  • 10. Enterprise Step 3: Open the URL from the website Go to the website from UI and copy our URL used in the controller, ie /sale_details here. The page will be loaded as below with all the details we specified using the template.
  • 11. For More Info. Check our company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com