In this slide, we’ll discuss on how to modify existing web pages in Odoo 18. Web pages in Odoo 18 can also gather user data through user-friendly forms, encourage interaction through engaging features.
Size: 366.69 KB
Language: en
Added: Mar 06, 2025
Slides: 13 pages
Slide Content
How to Modify Existing Web Pages in Odoo 18 Enterprise
Enterprise Introduction In this slide, we’ll discuss on how to modify existing web pages in Odoo 18. Web pages in Odoo 18 can also gather user data through user-friendly forms, encourage interaction through engaging features. However, through strategic modifications, we can transform this virtual real estate into a captivating showcase that captures visitors attention and propels them further into the sales funnel.
Enterprise Before adding the custom code in controller, we can add custom field in product_template model. from odoo import fields, models class ProductTemplate (models.Model) : _inherit = 'product.template' top_selling = fields.Boolean(string= 'Top selling' ) Next, to add this in the view, we can inherit the product_template model and add the field.
Enterprise Next, to add top selling products of the e-commerce website on the Home Page, we can use the code snippet to fetch the top-selling products based on their sales count within a specified date range and renders them on the homepage of the website. homepage template. We can add this code in the controller of the custom module. from odoo import http from odoo.http import request from odoo.addons.website.controllers.main import Home class Website (Home) : @http.route('/', auth="public", website=True, sitemap=True) def index (self, **kw) : """Initialize products' sales count and top-selling flag""" products = request.env[ 'product.template' ].sudo().search([])
Enterprise for product in products: product.sales_count = product.top_selling = False orders = request.env[ 'sale.order' ].sudo().search([ ( 'state' , 'in' , ( 'sale' , 'done' ))]) for order in orders: for line in order.order_line: line.product_id.sales_count += line.product_uom_qty website_product_ids = [product for product in products if product.sales_count != ] sorted_products = sorted(website_product_ids, key= lambda p: p.sales_count, reverse= True ) # Mark the top 4 products as top-selling for product in sorted_products[ 3 : 7 ]: product.top_selling = True
Enterprise # Render the homepage template with the sorted products return request.render( 'website.homepage' , { 'website_product_ids' : sorted_products[ 3 : 7 ]}) To incorporate these top-selling products into the homepage, we can inherit the website. Create a homepage template and add a container within the div with the ID wrap. <? xml version= "1.0" encoding= "UTF-8" ?> <odoo> <template id= "homepage_inherit_product_display" inherit_id= "website.homepage" name= "Products" active= "True" > <data inherit_id= "website.homepage" > <xpath expr= "//div[@id='wrap']" position= "inside" > <input type= "hidden" name= "csrf_token" t-att-value= "request.csrf_token()" />
Enterprise This code snippet iterates over the top-selling products and displays their name, image, and price within a product cart view on the homepage.
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