A Complete Technical Guide to Editing Existing Web Pages in Odoo 19

0
49

Modifying existing web pages in Odoo 19 is an essential capability for businesses that want to deliver a customized, engaging, and brand-aligned online presence. Whether you’re enhancing the homepage, adjusting product pages, or adding new dynamic sections, Odoo’s website framework provides a flexible structure built on QWeb templates, controllers, and views.

For an ERP Implementation Consultant, these customization techniques are vital, as clients often require tailored websites that still remain safe during upgrades and maintainable in the long run. Odoo achieves this through a clean inheritance system that allows modifications without altering core code.

Understanding How Web Pages Work in Odoo 19

The website module in Odoo 19 is powered by:

  • QWeb templates that define structure

  • Controllers that manage data and routing

  • Views that determine how elements appear

  • Assets (CSS/JS) that style and enhance the pages

When modifying any existing web page—like the homepage (website.homepage) or shop page (website_sale.products)—you must inherit the template rather than rewrite it. This ensures:

  • Compatibility with future Odoo updates

  • Clean separation of custom logic

  • Maintained core functionality

This guide walks through a practical example: adding a fully dynamic “Top Selling Products” section to the homepage using a custom module.


Step 1: Build a Custom Module Structure

To modify templates programmatically, you first create a dedicated Odoo module. This keeps changes organized and prevents direct edits in the Odoo core.

Folder Structure:

custom_website_mods/ │-- __init__.py-- __manifest__.py-- models/ │ ├── __init__.py │ └── product_template.py │-- controllers/ │ ├── __init__.py │ └── main.py └-- views/ └── homepage_templates.xml

Module Initialization Files

__init__.py (root):

 
from . import models, controllers

models/__init__.py:

 
from . import product_template

controllers/__init__.py:

 
from . import main

Module Manifest

The manifest controls dependencies and loaded files.

{ 'name': 'Custom Website Modifications', 'version': '19.0.1.0.0', 'category': 'Website', 'summary': 'Modify existing web pages through code', 'depends': ['website', 'website_sale'], 'data': [ 'views/homepage_templates.xml', ], 'installable': True, 'auto_install': False, }

Install via:
Apps → Update Apps List → Search “Custom Website Modifications” → Install


Step 2: Extend Models to Add Custom Product Fields

To display “Top Selling Products,” you must tag products. You can compute this from sales, but for simplicity, add a boolean field.

models/product_template.py:

from odoo import fields, models class ProductTemplate(models.Model): _inherit = 'product.template' is_top_selling = fields.Boolean( string='Top Selling', help='Mark this product as top-selling for homepage display.' )

This inheritance ensures that you never modify Odoo’s default product model directly.


Step 3: Inherit the Controller to Inject Custom Homepage Data

Controllers handle routing and supply data to QWeb templates.

controllers/main.py:

import odoo.http as http from odoo.http import request from odoo.addons.website.controllers.main import Website class WebsiteTopSelling(Website): @http.route('/', type='http', auth='public', website=True) def index(self, **kw): response = super(WebsiteTopSelling, self).index(**kw) top_products = request.env['product.template'].search([ ('is_top_selling', '=', True), ('website_published', '=', True), ], limit=4, order='sales_count desc') response.qcontext['top_selling_products'] = top_products return response

This override maintains the original homepage behavior while injecting additional data—a safe and recommended approach.


Step 4: Modify the Homepage Template Using QWeb & XPath

Odoo requires modifying templates using inheritance and XPath selectors.

views/homepage_templates.xml:

 
<?xml version="1.0" encoding="UTF-8"?> <odoo> <template id="homepage_top_selling" inherit_id="website.homepage" name="Top Selling Products Section"> <xpath expr="//div[@id='wrap']" position="inside"> <div class="container mt-5 mb-5"> <h2 class="text-center mb-4">Top Selling Products</h2> <div class="row"> <t t-foreach="top_selling_products" t-as="product"> <div class="col-md-3 mb-4"> <div class="card h-100"> <img t-att-src="product.image_1920 or '/web/static/src/img/placeholder.png'" class="card-img-top" alt="Product Image" style="height: 200px; object-fit: cover;"/> <div class="card-body d-flex flex-column"> <h5 class="card-title"><t t-esc="product.name"/></h5> <p class="card-text flex-grow-1"><t t-esc="product.list_price"/> €</p> <a t-att-href="'/shop/product/%s' % product.id" class="btn btn-primary mt-auto">View Product</a> </div> </div> </div> </t> </div> </div> </xpath> </template> </odoo>

This neatly inserts the new product section under the homepage’s main wrapper.


Step 5: Additional Advanced Page Modifications

Modifying Menus

To rename or hide menu items:

<record id="shop_menu_inherit" model="website.menu"> <field name="inherit_id" ref="website_sale.menu_shop_main"/> <field name="name">Products</field> </record>

To hide a menu:

<record id="blog_menu_hide" model="website.menu"> <field name="inherit_id" ref="website_blog.menu_blog_link"/> <field name="is_visible" eval="False"/> </record>

Creating Custom Static Pages

<template id="custom_page" name="Custom Page" page="True"> <t t-call="website.layout"> <div id="wrap" class="container"> <h1>My Custom Page</h1> </div> </t> </template>

Route:

@http.route('/custom', type='http', auth='public', website=True)

Adding Custom CSS/JS

In the manifest:

'assets': { 'web.assets_frontend': [ 'custom_website_mods/static/src/scss/custom.scss', 'custom_website_mods/static/src/js/custom.js', ], },

Conclusion

Modifying existing web pages in Odoo 19 is a powerful way to deliver tailored website features while maintaining upgrade safety. Using Odoo’s inheritance structure—model extensions, controller overrides, and QWeb template inheritance—you can enhance the homepage, adjust product displays, modify menus, or redesign entire layouts without touching the core framework.

For businesses aiming to create a branded, optimized website—or for an ERP Implementation Consultant responsible for building long-term scalable systems—these techniques are essential. As long as you follow Odoo’s best practices, your website remains maintainable, clean, and fully compatible with future Odoo upgrades.

Booking an implementation connsultant today.

Căutare
Categorii
Citeste mai mult
Alte
The Best SMM Panel for Real Estate Marketing
Introduction In today’s competitive real estate market, choosing the best SMM panel can...
By SMMJOBZ - smm panel 2025-09-14 20:51:37 0 2K
Fitness
Supra KETO BHB + ACV Gummies: #1 Doctor Recommended Formula for Weight Loss
Supra KETO ACV Gummies is a pioneering weight reduction supplement that has emerged as a popular...
By CalmEars Capsules 2025-07-30 18:40:25 0 2K
Fitness
Nutrical Apotek- Viktminskningstillskott, fördelar, ingredienser och effekt!
Klicka här för att köpa produkten:...
By Nutrical Gummies Nutrical Gummies 2025-05-30 11:07:38 0 6K
Alte
Almond Oil Market Trends, Growth Opportunities, and Forecast Outlook
"Latest Insights on Executive Summary Almond Oil Market Share and Size CAGR Value...
By Rahul Rangwa 2025-09-18 04:14:47 0 451
Health
Experience The Unique Offerings of BodyCode Keto Weight Loss Supplement Australia – Price For Sale
The ketogenic diet, frequently referred to as the keto diet, has experienced a remarkable rise in...
By Bodycodeketo Sale 2025-07-19 07:56:34 0 3K
JogaJog https://jogajog.com.bd