|
| 1 | +=================== |
| 2 | +Chapter 1 - Theming |
| 3 | +=================== |
| 4 | + |
| 5 | +Now that you have Odoo installed and your server is running locally, it's time to create your own |
| 6 | +theme module for your website. |
| 7 | + |
| 8 | +.. _tutorials/website_theme/theming/setup: |
| 9 | + |
| 10 | +Setup |
| 11 | +===== |
| 12 | + |
| 13 | +| The first step is to ensure that Odoo is running correctly locally. To do this, use a Shell script |
| 14 | + to run the server. |
| 15 | +| In this script, define the database name and install only the `website` module. |
| 16 | +
|
| 17 | +.. seealso:: |
| 18 | + See reference documentation on how to :ref:`run Odoo <website_themes/setup/getting_started>`. |
| 19 | + |
| 20 | +.. _tutorials/website_theme/theming/module: |
| 21 | + |
| 22 | +Build your module structure |
| 23 | +=========================== |
| 24 | + |
| 25 | +Now that we know everything is working properly, let's start building our module. |
| 26 | + |
| 27 | +Based on the following structure, start creating your module that will be used as a theme. This is |
| 28 | +where you are going to add your XML pages, SCSS, JS, … |
| 29 | + |
| 30 | +.. seealso:: |
| 31 | + See reference documentation on how to structure your :ref:`theming/module`. |
| 32 | + |
| 33 | +| Start with the basics : :file:`/data`, :file:`/img`, :file:`/scss`, :file:`/js`. |
| 34 | +| Don't forget to add the :file:`__init__.py` and :file:`__manifest__.py` files. |
| 35 | +
|
| 36 | +In your :file:`__manifest__.py` file, you can declare your module with the following information: |
| 37 | + |
| 38 | +- name (required) |
| 39 | +- description |
| 40 | +- category |
| 41 | +- version |
| 42 | +- author |
| 43 | +- license |
| 44 | +- depends |
| 45 | + |
| 46 | +.. _tutorials/website_theme/theming/odoo_variables: |
| 47 | + |
| 48 | +Declare Odoo variables |
| 49 | +====================== |
| 50 | + |
| 51 | +In the :file:`primary_variables.scss` file, you can override the default Odoo SCSS variables to |
| 52 | +match your design. |
| 53 | + |
| 54 | +Based on the Airproof design, create your :file:`primary_variables.scss` file and define the |
| 55 | +following elements: |
| 56 | + |
| 57 | +- Headings font family : Space Grotesk |
| 58 | +- Content font family : Lato |
| 59 | +- The color palette name and the 5 main colors that compose it: `#000000`, `#BBE1FA`, `#CEF8A1`, |
| 60 | + `#FFFFFF`, `#0B8EE6` |
| 61 | +- Header & Footer : Use one of the default templates for the moment, we will create a custom header |
| 62 | + later. |
| 63 | + |
| 64 | +.. seealso:: |
| 65 | + See reference documentation on how to use :ref:`primary variables <theming/module/variables>`, as |
| 66 | + well as a list of all `primary variables |
| 67 | + <{GITHUB_PATH}/addons/website/static/src/scss/primary_variables.scss>`_ available. |
| 68 | + |
| 69 | +| Restart your script to immediately see the application of your changes. |
| 70 | +| Don't forget to add the path to your manifest in the script and set your module as the app |
| 71 | + to install. |
| 72 | +
|
| 73 | +To ensure your changes are applied correctly, log in to your website and check that your |
| 74 | +color palette includes your specified colors. |
| 75 | + |
| 76 | +.. tip:: |
| 77 | + You will need to override more variables to replicate the Airproof design. Remember to add them |
| 78 | + throughout the creation of your website. |
| 79 | + |
| 80 | +.. note:: |
| 81 | + The font families are from `Google fonts <https://fonts.google.com/>`_. |
| 82 | + |
| 83 | +.. spoiler:: Solutions |
| 84 | + |
| 85 | + To complete this exercise, you need to: |
| 86 | + |
| 87 | + #. Create your :file:`primary_variables.scss` file. You can find all the necessary information in |
| 88 | + the `primary_variables.scss |
| 89 | + <{GITHUB_TUTO_PATH}/website_airproof/static/src/scss/primary_variables.scss>`_ file from our |
| 90 | + example module. |
| 91 | + #. Declare your file in the :file:`__manifest__.py` as indicated in the documentation. |
| 92 | + #. Install your module via your script. In our example, it looks like this: |
| 93 | + |
| 94 | + .. code-block:: xml |
| 95 | +
|
| 96 | + ./odoo-bin --addons-path=../enterprise,addons,../myprojects --db-filter=theming -d theming |
| 97 | + --without-demo=all -i website_airproof --dev=xml |
| 98 | +
|
| 99 | +.. _tutorials/website_theme/theming/bootstrap_variab
1241
les: |
| 100 | + |
| 101 | +Declare Bootstrap variables |
| 102 | +=========================== |
| 103 | + |
| 104 | +On top of the default Odoo variables, you can also redefine the Bootstrap variables. Bootstrap is a |
| 105 | +front-end framework which is included by default in Odoo. |
| 106 | + |
| 107 | +Based on the Airproof design, define the following elements: |
| 108 | + |
| 109 | +- Headings font sizes : |
| 110 | + |
| 111 | + - h1 : 3.125rem |
| 112 | + - h2 : 2.5rem |
| 113 | + - h3 : 2rem |
| 114 | + - h4 : 1.75rem |
| 115 | + - h5 : 1.5rem |
| 116 | + - h6 : 1.25rem |
| 117 | + |
| 118 | +- Inputs border radius : 10px |
| 119 | +- Inputs border color : black |
| 120 | +- Inputs border width : 1px |
| 121 | +- Large buttons border radius : 0px 10px 10px 10px |
| 122 | + |
| 123 | +.. seealso:: |
| 124 | + - See reference documentation on how to use :ref:`theming/module/bootstrap`. |
| 125 | + - A list of all `Bootstrap variables |
| 126 | + <{GITHUB_PATH}/addons/web/static/lib/bootstrap/scss/_variables.scss>`_ used by Odoo. |
| 127 | + - And `Bootstrap framework <https://getbootstrap.com/docs/4.6/getting-started/introduction/>`_ |
| 128 | + official documentation. |
| 129 | + |
| 130 | +.. tip:: |
| 131 | + - You will need to override more variables to replicate the Airproof design. Remember to add them |
| 132 | + throughout the creation of your website. |
| 133 | + - Make it a habit to regularly check locally that your changes have been successfully applied |
| 134 | + and have not caused any errors. |
| 135 | + |
| 136 | +.. spoiler:: Solutions |
| 137 | + |
| 138 | + To complete this exercise, you need to: |
| 139 | + |
| 140 | + #. Create your :file:`bootstrap_overridden.scss` file. You can find all the necessary information |
| 141 | + in the `bootstrap_overridden.scss |
| 142 | + <{GITHUB_TUTO_PATH}/website_airproof/static/src/scss/bootstrap_overridden.scss>`_ file from |
| 143 | + our example module. |
| 144 | + #. Declare your file in the :file:`__manifest__.py` as indicated in the documentation. |
| 145 | + |
| 146 | +.. _tutorials/website_theme/theming/presets: |
| 147 | + |
| 148 | +Define presets |
| 149 | +============== |
| 150 | + |
| 151 | +In addition to the variables we have just covered, you can also activate specific views to modify |
| 152 | +the design. |
| 153 | + |
| 154 | +Add your :file:`presets.xml` file and based on the Airproof design, activate the appropriate views |
| 155 | +to meet the following client requests: |
| 156 | + |
| 157 | +- Deactivate the Call-to-action in the header. |
| 158 | +- Deactivate the wishlist feature in the shop but activate it on the product page. |
| 159 | +- On the shop page, activate the filtering by categories only on the left side. |
| 160 | + |
| 161 | +.. seealso:: |
| 162 | + | See how you can define your :ref:`presets <theming/module/views/presets>`. |
| 163 | + | To start writing your file, follow the instructions for any Odoo XML page described in |
| 164 | + :doc:`/developer/howtos/website_themes/layout`. |
| 165 | +
|
| 166 | +.. tip:: |
| 167 | + - To complete the exercise, you need to install the **eCommerce** (`website_sale`) and |
| 168 | + **wishlist** (`website_sale_whishlist`) applications. **Be careful!** Referencing an |
| 169 | + application in your code that hasn't been installed will result in an error. |
| 170 | + - | In order to find the templates to activate or not, go to the source code: |
| 171 | + `odoo/addons/website/views/**`. |
| 172 | + | For example, you can find all the templates for the header in |
| 173 | + `website_templates.xml <{GITHUB_PATH}/addons/website/views/website_templates.xml>`_. |
| 174 | + - To see the effect of your presets, add some **products** (*Airproof Mini*, *Airproof Robin*, |
| 175 | + *Warranty*, *Charger cable*) and create **eCommerce categories** (*Warranties*, *Accessories*, |
| 176 | + and *Drones* with *Camera drones* and *Waterproof drones*) in the database. You will find the |
| 177 | + `product images here <{GITHUB_TUTO_PATH}/website_airproof/static/src/img/content>`_. |
| 178 | + - You will need to activate more views to replicate the Airproof design. Remember to add them |
| 179 | + throughout the creation of your website. |
| 180 | + |
| 181 | +.. spoiler:: Solutions |
| 182 | + |
| 183 | + To deactivate the Call-to-action: |
| 184 | + |
| 185 | + #. The view you have to find is in :file:`odoo/addons/website/views/website_templates.xml l:2113` |
| 186 | + #. Create your :file:`presets.xml` file with the right records |
| 187 | + |
| 188 | + .. code-block:: xml |
| 189 | + :caption: ``/website_airproof/data/presets.xml`` |
| 190 | +
|
| 191 | + <?xml version="1.0" encoding="utf-8"?> |
| 192 | + <odoo> |
| 193 | + <!-- Disable Call-to-action in header --> |
| 194 | + <record id="website.header_call_to_action" model="ir.ui.view"> |
| 195 | + <field name="active" eval="False"/> |
| 196 | + </record> |
| 197 | + </odoo> |
| 198 | + #. In the manifest, add the 2 apps and declare your file. |
| 199 | + |
| 200 | + .. code-block:: python |
| 201 | + :caption: ``/website_airproof/__manifest__.py`` |
| 202 | +
|
| 203 | + 'depends': ['website_sale', 'website_sale_wishlist'], |
| 204 | + 'data': [ |
| 205 | + # Options |
| 206 | + 'data/presets.xml', |
| 207 | + ] |
0 commit comments