Chapter 1 - Theming¶
Now that you have Odoo installed and your server is running locally, it’s time to create your own theme module for your website.
Setup¶
website
module.Vedi anche
See reference documentation on how to run Odoo.
Build your module structure¶
Now that we know everything is working properly, let’s start building our module.
Based on the following structure, start creating your module that will be used as a theme. This is where you are going to add your XML pages, SCSS, JS, …
Vedi anche
See reference documentation on how to structure your Theme module.
/data
, /img
, /scss
, /js
.__init__.py
and __manifest__.py
files.In your __manifest__.py
file, you can declare your module with the following information:
name (required)
description
category
version
author
license
depends
Declare Odoo variables¶
In the primary_variables.scss
file, you can override the default Odoo SCSS variables to
match your design.
Based on the Airproof design, create your primary_variables.scss
file and define the
following elements:
Headings font family : Space Grotesk
Content font family : Lato
The color palette name and the 5 main colors that compose it:
#000000
,#BBE1FA
,#CEF8A1
,#FFFFFF
,#0B8EE6
Header & Footer : Use one of the default templates for the moment, we will create a custom header later.
Vedi anche
See reference documentation on how to use primary variables, as well as a list of all primary variables available.
To ensure your changes are applied correctly, log in to your website and check that your color palette includes your specified colors.
Suggerimento
You will need to override more variables to replicate the Airproof design. Remember to add them throughout the creation of your website.
Nota
The font families are from Google fonts.
To complete this exercise, you need to:
Create your
primary_variables.scss
file. You can find all the necessary information in the primary_variables.scss file from our example module.Declare your file in the
__manifest__.py
as indicated in the documentation.Install your module via your script. In our example, it looks like this:
./odoo-bin --addons-path=../enterprise,addons,../myprojects --db-filter=theming -d theming
--without-demo=all -i website_airproof --dev=xml
Declare Bootstrap variables¶
On top of the default Odoo variables, you can also redefine the Bootstrap variables. Bootstrap is a front-end framework which is included by default in Odoo.
Based on the Airproof design, define the following elements:
Headings font sizes :
h1 : 3.125rem
h2 : 2.5rem
h3 : 2rem
h4 : 1.75rem
h5 : 1.5rem
h6 : 1.25rem
Inputs border radius : 10px
Inputs border color : black
Inputs border width : 1px
Large buttons border radius : 0px 10px 10px 10px
Vedi anche
See reference documentation on how to use Bootstrap variables.
A list of all Bootstrap variables used by Odoo.
And Bootstrap framework official documentation.
Suggerimento
You will need to override more variables to replicate the Airproof design. Remember to add them throughout the creation of your website.
Make it a habit to regularly check locally that your changes have been successfully applied and have not caused any errors.
To complete this exercise, you need to:
Create your
bootstrap_overridden.scss
file. You can find all the necessary information in the bootstrap_overridden.scss file from our example module.Declare your file in the
__manifest__.py
as indicated in the documentation.
Define presets¶
In addition to the variables we have just covered, you can also activate specific views to modify the design.
Add your presets.xml
file and based on the Airproof design, activate the appropriate views
to meet the following client requests:
Deactivate the Call-to-action in the header.
Deactivate the wishlist feature in the shop but activate it on the product page.
On the shop page, activate the filtering by categories only on the left side.
Vedi anche
Suggerimento
To complete the exercise, you need to install the eCommerce (
website_sale
) and wishlist (website_sale_whishlist
) applications. Be careful! Referencing an application in your code that hasn’t been installed will result in an error.- In order to find the templates to activate or not, go to the source code:
odoo/addons/website/views/**
.For example, you can find all the templates for the header in website_templates.xml. To see the effect of your presets, add some products (Airproof Mini, Airproof Robin, Warranty, Charger cable) and create eCommerce categories (Warranties, Accessories, and Drones with Camera drones and Waterproof drones) in the database. You will find the product images here.
You will need to activate more views to replicate the Airproof design. Remember to add them throughout the creation of your website.
To deactivate the Call-to-action:
The view you have to find is in
odoo/addons/website/views/website_templates.xml l:2113
Create your
presets.xml
file with the right records/website_airproof/data/presets.xml
¶<?xml version="1.0" encoding="utf-8"?> <odoo> <!-- Disable Call-to-action in header --> <record id="website.header_call_to_action" model="ir.ui.view"> <field name="active" eval="False"/> </record> </odoo>
In the manifest, add the 2 apps and declare your file.
/website_airproof/__manifest__.py
¶'depends': ['website_sale', 'website_sale_wishlist'], 'data': [ # Options 'data/presets.xml', ]