SlideShare a Scribd company logo
4
Most read
13
Most read
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
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="product_template_form_view"
model="ir.ui.view">
<field
name="name">product.template.inherit.view.form</field>
<field name="model">product.template</field>
<field name="inherit_id"
ref="product.product_template_form_view"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='taxes_id']"
position="after">
<field name="top_selling"/>
</xpath>
</field>
</record>
</odoo>
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 = 0
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 != 0]
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
<div class="container mt32 mb64">
<section>
<div class="product_details">
<center>
<h3>MOST SELLING
PRODUCTS</h3>
</center>
</div>
<br/>
<div class="oe_product_cart_new row"
style="overflow: hidden;">
<t t-
foreach="website_product_ids"
t-as="website_product_id">
<div class="col-md-3 col-sm-3
col-xs-12" style="padding:6px 6px 6px 6px;">
<form
action="/shop/cart/update" method="post" class="card
oe_product_cart" data-publish="on">
<br/>
<center>
Enterprise
<div style="width:100%;
height:155px;overflow: hidden;">
<a
t-attf-href="/shop/product/#{ slug(website_product_id) }">
<img
t-attf-src="/web/image?
model=product.template&amp;field=image_1920&amp;id=#{websit
e_product_id.id}" class="img img-fluid"
style="padding: 0px; margin:
0px; width:auto; height:100%;"/>
</a>
</div>
</center>
<br/>
<div class="card-body p-0 text-center
o_wsale_product_information">
<div class="p-2
o_wsale_product_information_text">
<h6 class="o_wsale_products_item_title">
Enterprise
<a data-oe-model="product.template" data-oe-
id="website_product_id.id"
data-oe-field="website_product_id.name"
data-oe-type="char"
data-oe-
expression="product.name"
itemprop="name"
data-oe-field-xpath="/t[1]/form[1]/div[2]/div[1]/h6[1]/a[1]
" t-attf-
href="/shop/product/#{ slug(website_product_id) }"
content="website_product_id.name">
<t t-
esc="website_product_id.name"/>
</a>
</h6>
<h6 class="o_wsale_products_item_title">
<span t-
esc="website_product_id.currency_id.symbol"
style="color:black"/>
<t t-esc="website_product_id.list_price"/>
</h6>
</div>
Enterprise
<div class="o_wsale_product_btn"
data-oe-model="ir.ui.view"
data-oe-id="1561" data-oe-
field="arch" data-oe-
xpath="/t[1]/form[1]/div[2]/div[2]"/>
</div>
<span class="o_ribbon " style=""/>
</form>
</div>
</t>
</div>
</section>
</div>
</xpath>
</data>
</template>
</odoo>
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

More Related Content

PPTX
URLs and Routing in the Odoo 17 Website App
PPTX
URLS and routing in odoo 18 - Odoo Slides
PPTX
How to Add Pagination in Website portal in Odoo
PPTX
Building A Website - URLs and routing
PPTX
How to Create a Dynamic Snippet in Odoo 17
PPTX
Qweb Templates and Operations in Odoo 18
PPTX
Make Your Odoo Theme Features Integration Easier With Seamless Odoo Learning ...
PPTX
How to Create & Manage a Dashboard Using OWL in Odoo 17
URLs and Routing in the Odoo 17 Website App
URLS and routing in odoo 18 - Odoo Slides
How to Add Pagination in Website portal in Odoo
Building A Website - URLs and routing
How to Create a Dynamic Snippet in Odoo 17
Qweb Templates and Operations in Odoo 18
Make Your Odoo Theme Features Integration Easier With Seamless Odoo Learning ...
How to Create & Manage a Dashboard Using OWL in Odoo 17

Similar to How to Modify Existing Web Pages in Odoo 18 (20)

PPTX
How to use upsell &amp; cross sell in odoo 13 e commerce
PPTX
How to Sell Your Products in Odoo 17 Website
PDF
Goodrelations Presentation from SemTech 2010
PPTX
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
PDF
Nosto (2017) The Anatomy of a Successful Ecommerce Store.pdf
PDF
Odoo eCommerce Features
PDF
Goodrelations semtech2010
PDF
SEO, RDFa, and GoodRelations - An Implementation by a Major Online Retailer
PDF
SEO, RDFa, and GoodRelations: An Implementation by a Major Online Retailer
PDF
Odoo Crafito Theme, Multipurpose Odoo Template For All Industries
PPTX
BelVG: Prestashop tips and tricks
PPTX
How to Customize Website in Odoo 13
PPTX
How to perform product search based on a custom field from the PoS screen of ...
PPTX
Create Products in Odoo 15
PPTX
Odoo Experience 2018 - Tutorial: How to Create an Awesome eCommerce Website?
PPTX
Ecommerce dev for business needs
PPTX
How to add menu in Odoo 17 Website - Odoo 17 Slides
PPT
Odoo website themes
PPTX
Revamp in Product View in Odoo 18 - Odoo 18 Slides
PPTX
How to Create a Customer From Website in Odoo 18.pptx
How to use upsell &amp; cross sell in odoo 13 e commerce
How to Sell Your Products in Odoo 17 Website
Goodrelations Presentation from SemTech 2010
How to Add a Custom Menu, List view and FIlters in the Customer Portal Odoo 18
Nosto (2017) The Anatomy of a Successful Ecommerce Store.pdf
Odoo eCommerce Features
Goodrelations semtech2010
SEO, RDFa, and GoodRelations - An Implementation by a Major Online Retailer
SEO, RDFa, and GoodRelations: An Implementation by a Major Online Retailer
Odoo Crafito Theme, Multipurpose Odoo Template For All Industries
BelVG: Prestashop tips and tricks
How to Customize Website in Odoo 13
How to perform product search based on a custom field from the PoS screen of ...
Create Products in Odoo 15
Odoo Experience 2018 - Tutorial: How to Create an Awesome eCommerce Website?
Ecommerce dev for business needs
How to add menu in Odoo 17 Website - Odoo 17 Slides
Odoo website themes
Revamp in Product View in Odoo 18 - Odoo 18 Slides
How to Create a Customer From Website in Odoo 18.pptx
Ad

More from Celine George (20)

PPTX
How to Implement OWL Notification Service in Odoo 18
PPTX
Tracking Profit Margins in Sales Orders with Odoo 18
PPTX
How to Configure Outgoing Shipment in 3 Steps Using Odoo 18
PPTX
How to Configure Outgoing Shipment in 1 Step Using Odoo 18.pptx
PPTX
How to Configure Outgoing Shipment in 2 Steps Using Odoo 18
PPTX
How to Add New Applicants in Odoo 18 Recruitment
PPTX
How to Analyze the Recruitment Process in Odoo 18 Recruitment
PPTX
How to Manage Referral Reporting in Odoo 18 Referrals
PPTX
How to Set, Track, & Review Employee Goals in Odoo 18 Appraisals
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PPTX
How to Manage Starshipit in Odoo 18 - Odoo Slides
PPTX
How to Manage Bill Control Policy in Odoo 18
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PPTX
Odoo 18 Sales_ Managing Quotation Validity
PPTX
How to Manage Global Discount in Odoo 18 POS
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
How to Implement OWL Notification Service in Odoo 18
Tracking Profit Margins in Sales Orders with Odoo 18
How to Configure Outgoing Shipment in 3 Steps Using Odoo 18
How to Configure Outgoing Shipment in 1 Step Using Odoo 18.pptx
How to Configure Outgoing Shipment in 2 Steps Using Odoo 18
How to Add New Applicants in Odoo 18 Recruitment
How to Analyze the Recruitment Process in Odoo 18 Recruitment
How to Manage Referral Reporting in Odoo 18 Referrals
How to Set, Track, & Review Employee Goals in Odoo 18 Appraisals
Revamp in MTO Odoo 18 Inventory - Odoo Slides
How to Manage Starshipit in Odoo 18 - Odoo Slides
How to Manage Bill Control Policy in Odoo 18
How to Manage Loyalty Points in Odoo 18 Sales
Odoo 18 Sales_ Managing Quotation Validity
How to Manage Global Discount in Odoo 18 POS
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Tips Management in Odoo 18 POS - Odoo Slides
How to Close Subscription in Odoo 18 - Odoo Slides
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
How to Track Skills & Contracts Using Odoo 18 Employee
Ad

Recently uploaded (20)

PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
Complications of Minimal Access Surgery at WLH
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Basic Mud Logging Guide for educational purpose
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PDF
RMMM.pdf make it easy to upload and study
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Sports Quiz easy sports quiz sports quiz
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
Complications of Minimal Access Surgery at WLH
FourierSeries-QuestionsWithAnswers(Part-A).pdf
GDM (1) (1).pptx small presentation for students
Basic Mud Logging Guide for educational purpose
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
RMMM.pdf make it easy to upload and study
2.FourierTransform-ShortQuestionswithAnswers.pdf
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
102 student loan defaulters named and shamed – Is someone you know on the list?
PPH.pptx obstetrics and gynecology in nursing
Microbial disease of the cardiovascular and lymphatic systems
Sports Quiz easy sports quiz sports quiz
STATICS OF THE RIGID BODIES Hibbelers.pdf
VCE English Exam - Section C Student Revision Booklet
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student

How to Modify Existing Web Pages in Odoo 18

  • 1. How to Modify Existing Web Pages in Odoo 18 Enterprise
  • 2. 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.
  • 3. 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.
  • 4. Enterprise <?xml version="1.0" encoding="UTF-8" ?> <odoo> <record id="product_template_form_view" model="ir.ui.view"> <field name="name">product.template.inherit.view.form</field> <field name="model">product.template</field> <field name="inherit_id" ref="product.product_template_form_view"/> <field name="arch" type="xml"> <xpath expr="//field[@name='taxes_id']" position="after"> <field name="top_selling"/> </xpath> </field> </record> </odoo>
  • 5. 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([])
  • 6. Enterprise for product in products: product.sales_count = 0 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 != 0] 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
  • 7. 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()"/>
  • 8. Enterprise <div class="container mt32 mb64"> <section> <div class="product_details"> <center> <h3>MOST SELLING PRODUCTS</h3> </center> </div> <br/> <div class="oe_product_cart_new row" style="overflow: hidden;"> <t t- foreach="website_product_ids" t-as="website_product_id"> <div class="col-md-3 col-sm-3 col-xs-12" style="padding:6px 6px 6px 6px;"> <form action="/shop/cart/update" method="post" class="card oe_product_cart" data-publish="on"> <br/> <center>
  • 9. Enterprise <div style="width:100%; height:155px;overflow: hidden;"> <a t-attf-href="/shop/product/#{ slug(website_product_id) }"> <img t-attf-src="/web/image? model=product.template&amp;field=image_1920&amp;id=#{websit e_product_id.id}" class="img img-fluid" style="padding: 0px; margin: 0px; width:auto; height:100%;"/> </a> </div> </center> <br/> <div class="card-body p-0 text-center o_wsale_product_information"> <div class="p-2 o_wsale_product_information_text"> <h6 class="o_wsale_products_item_title">
  • 10. Enterprise <a data-oe-model="product.template" data-oe- id="website_product_id.id" data-oe-field="website_product_id.name" data-oe-type="char" data-oe- expression="product.name" itemprop="name" data-oe-field-xpath="/t[1]/form[1]/div[2]/div[1]/h6[1]/a[1] " t-attf- href="/shop/product/#{ slug(website_product_id) }" content="website_product_id.name"> <t t- esc="website_product_id.name"/> </a> </h6> <h6 class="o_wsale_products_item_title"> <span t- esc="website_product_id.currency_id.symbol" style="color:black"/> <t t-esc="website_product_id.list_price"/> </h6> </div>
  • 11. Enterprise <div class="o_wsale_product_btn" data-oe-model="ir.ui.view" data-oe-id="1561" data-oe- field="arch" data-oe- xpath="/t[1]/form[1]/div[2]/div[2]"/> </div> <span class="o_ribbon " style=""/> </form> </div> </t> </div> </section> </div> </xpath> </data> </template> </odoo>
  • 12. 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.
  • 13. 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