KEMBAR78
How to add menu in Odoo 17 Website - Odoo 17 Slides | PPTX
How to add menu in
Odoo Website
Enterprise
Enterprise
Introduction
Creating a menu in Odoo from website front end is not a big deal. From
the backend, website development involves using Odoo's website builder
tools and some customization.
We can check how it is done in the Odoo 17
Enterprise
To create a menu in the website, let’s create a record in xml code for the
model ‘website.menu’. We can give the attributes like name, parent, url,
etc. The code is as follows.
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="menu_booking" model="website.menu">
<field name="name">Booking</field>
<field name="url">/book_travel</field>
<field name="parent_id" ref="website.main_menu"/>
<field name="sequence" type="int">20</field>
</record>
</odoo>
Enterprise
Here, the properties
● Name is to enter the name of the menu item.
● Url is for entering the URL for the menu item. This can be an
internal link (e.g., /about-us) or an external link.
● parent_id: If you want to create a submenu, select the parent
menu item from the dropdown.
● sequence says the sequence order the menu is to be shown.
Then, give the view’s file name in the manifest of the module
Enterprise
This will show the menu as
Enterprise
On clicking the menu, a call will be passed to the controller which contains
the URL (ie here ‘/book_travel’).
Either we can render a template or we can redirect to a page from the
controller using controller ‘/book_travel’.
The controller .py file is usually stored inside the directory ‘controllers’
under the main directory of the module. Here, the controller code to
render the template with the details of a custom model travel.booking is
in the next page.
Enterprise
TravelData is the controller class of type http. Then, using the
@http.route, we define the method for the earlier defined URL
/book_travel.
In the variable values, the needed parameters from the custom model is
saved and passed while rendering the template
travel_management.booking_details.
from odoo import http
from odoo.http import request
class TravelData(http.Controller):
@http.route('/book_travel', type='http', auth="public", website=True)
def travel_booking_info(self, **arg):
booking_detail = request.env['travel.booking'].sudo().search([])
values = {'booking': booking_detail}
return request.render('travel_management.booking_details', values)
Enterprise
Then, design the code for the template as
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="booking_details" name="Travel Booking">
<t t-call="website.layout">
<center><h2>Travel Booking Details</h2></center>
<div class="oe_structure oe_empty">
<div class="container">
<t t-set="i" t-value="1"/>
<t t-foreach="booking" t-as="o">
<div>
<br/><h3> Booking <t t-esc="i"/></h3>
<h6 t-field="o.partner_id.name"/>
<h6 t-field="o.partner_mobile"/>
<h6 t-field="o.passenger_count"/>
</div>
<t t-set="i" t-value="i+1"/>
</t>
</div>
</div>
</t>
</template>
</odoo>
Enterprise
This will show the web page as
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

How to add menu in Odoo 17 Website - Odoo 17 Slides

  • 1.
    How to addmenu in Odoo Website Enterprise
  • 2.
    Enterprise Introduction Creating a menuin Odoo from website front end is not a big deal. From the backend, website development involves using Odoo's website builder tools and some customization. We can check how it is done in the Odoo 17
  • 3.
    Enterprise To create amenu in the website, let’s create a record in xml code for the model ‘website.menu’. We can give the attributes like name, parent, url, etc. The code is as follows. <?xml version="1.0" encoding="utf-8"?> <odoo> <record id="menu_booking" model="website.menu"> <field name="name">Booking</field> <field name="url">/book_travel</field> <field name="parent_id" ref="website.main_menu"/> <field name="sequence" type="int">20</field> </record> </odoo>
  • 4.
    Enterprise Here, the properties ●Name is to enter the name of the menu item. ● Url is for entering the URL for the menu item. This can be an internal link (e.g., /about-us) or an external link. ● parent_id: If you want to create a submenu, select the parent menu item from the dropdown. ● sequence says the sequence order the menu is to be shown. Then, give the view’s file name in the manifest of the module
  • 5.
  • 6.
    Enterprise On clicking themenu, a call will be passed to the controller which contains the URL (ie here ‘/book_travel’). Either we can render a template or we can redirect to a page from the controller using controller ‘/book_travel’. The controller .py file is usually stored inside the directory ‘controllers’ under the main directory of the module. Here, the controller code to render the template with the details of a custom model travel.booking is in the next page.
  • 7.
    Enterprise TravelData is thecontroller class of type http. Then, using the @http.route, we define the method for the earlier defined URL /book_travel. In the variable values, the needed parameters from the custom model is saved and passed while rendering the template travel_management.booking_details. from odoo import http from odoo.http import request class TravelData(http.Controller): @http.route('/book_travel', type='http', auth="public", website=True) def travel_booking_info(self, **arg): booking_detail = request.env['travel.booking'].sudo().search([]) values = {'booking': booking_detail} return request.render('travel_management.booking_details', values)
  • 8.
    Enterprise Then, design thecode for the template as <?xml version="1.0" encoding="utf-8"?> <odoo> <template id="booking_details" name="Travel Booking"> <t t-call="website.layout"> <center><h2>Travel Booking Details</h2></center> <div class="oe_structure oe_empty"> <div class="container"> <t t-set="i" t-value="1"/> <t t-foreach="booking" t-as="o"> <div> <br/><h3> Booking <t t-esc="i"/></h3> <h6 t-field="o.partner_id.name"/> <h6 t-field="o.partner_mobile"/> <h6 t-field="o.passenger_count"/> </div> <t t-set="i" t-value="i+1"/> </t> </div> </div> </t> </template> </odoo>
  • 9.
  • 10.
    For More Info. Checkour company website for related blogs and Odoo book. Check our YouTube channel for functional and technical videos in Odoo. Enterprise www.cybrosys.com