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

CelineGeorge1 960 views 10 slides Aug 23, 2024
Slide 1
Slide 1 of 10
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10

About This Presentation

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.


Slide Content

How to add menu in Odoo Website Enterprise

Enterprise Introduction Creating a menu in Odoo from website front end i s 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. s equence 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