diff --git a/web_theme_classic/README.rst b/web_theme_classic/README.rst new file mode 100644 index 000000000000..5825ab46e06f --- /dev/null +++ b/web_theme_classic/README.rst @@ -0,0 +1,132 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +================= +Web Theme Classic +================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:96a272ee896986cd77dc37d08d7df63ad97290bbe73d90c2ac25139644f4ae70 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb-lightgray.png?logo=github + :target: https://github.com/OCA/web/tree/18.0/web_theme_classic + :alt: OCA/web +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/web-18-0/web-18-0-web_theme_classic + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/web&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the Odoo Community Edition ``web`` module to improve +the visibility of input fields. + +**Rational:** Since Odoo V17, the design is very pure. That's great, but +it generates some problem for users : + +- Fields are not identifiable. (we can not know exactly where they are + until you hover over them with the cursor) +- There is no indication for the required fields until trying to save + (or exit the screen) + +In a way, this module restores the form display of version 15, but +preserving the "save on the fly" new feature. + +**Without this module** + +|image1| + +**With this module** + +|image2| + +.. |image1| image:: https://raw.githubusercontent.com/OCA/web/18.0/web_theme_classic/static/description/product_template_form_without_module.png +.. |image2| image:: https://raw.githubusercontent.com/OCA/web/18.0/web_theme_classic/static/description/product_template_form_with_module.png + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +This module allows each user to choose whether they would like input +fields to be displayed the "classic" way or the new, standard way (as if +this module were not installed) + +To do this you can either: + +- Check "Classic Theme Persistent" in user preferences. This will enable + the classic theme for that user across all devices. +- Check the "Classic Theme" toggle in the popover menu triggered bu + clicking on the user icon in the navbar. This toggle is only visible + when "Classic Theme Persistent" is disabled. + +Please note that when disabling "Classic Theme Persistent" the style +will not change until the page is reloaded. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* GRAP + +Contributors +------------ + +- Sylvain LE GAL (https://www.twitter.com/legalsylvain) +- `Pyxiris `__ + + - `Liam Noonan `__ + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +.. |maintainer-legalsylvain| image:: https://github.com/legalsylvain.png?size=40px + :target: https://github.com/legalsylvain + :alt: legalsylvain + +Current `maintainer `__: + +|maintainer-legalsylvain| + +This module is part of the `OCA/web `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/web_theme_classic/__init__.py b/web_theme_classic/__init__.py new file mode 100644 index 000000000000..0650744f6bc6 --- /dev/null +++ b/web_theme_classic/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/web_theme_classic/__manifest__.py b/web_theme_classic/__manifest__.py new file mode 100644 index 000000000000..02121e422743 --- /dev/null +++ b/web_theme_classic/__manifest__.py @@ -0,0 +1,38 @@ +# Copyright (C) 2022 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# © 2025 Liam Noonan - Pyxiris +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "Web Theme Classic", + "summary": "Contrasted style on fields to improve the UI.", + "version": "19.0.1.0.0", + "author": "GRAP, Odoo Community Association (OCA)", + "maintainers": ["legalsylvain"], + "website": "https://github.com/OCA/web", + "license": "AGPL-3", + "category": "Extra Tools", + "depends": [ + "web", + ], + "data": [ + "views/res_users_views.xml", + ], + "assets": { + "web.assets_backend": [ + "web_theme_classic/static/src/js/switch_theme.esm.js", + ], + "web.assets_web": [ + "/web_theme_classic/static/src/scss/web_theme_classic.scss", + ], + "web.assets_web_dark": [ + ( + "before", + "/web_theme_classic/static/src/scss/web_theme_classic.scss", + "/web_theme_classic/static/src/scss/web_theme_classic.dark.scss", + ), + ], + }, + "installable": True, + "application": True, +} diff --git a/web_theme_classic/i18n/fi.po b/web_theme_classic/i18n/fi.po new file mode 100644 index 000000000000..99d54022d8be --- /dev/null +++ b/web_theme_classic/i18n/fi.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_theme_classic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: fi\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: web_theme_classic +#. odoo-javascript +#: code:addons/web_theme_classic/static/src/js/switch_theme.esm.js:0 +msgid "Classic Theme" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users__persistent_classic_theme +msgid "Classic Theme Persistent" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_ir_http +msgid "HTTP Routing" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users_settings__persistent_classic_theme +msgid "Persistent Classic Theme" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,help:web_theme_classic.field_res_users__persistent_classic_theme +msgid "" +"This enables Classic Theme on this user's account across all devices. \n" +" Disabling it will will alow you to to use the toggle in the user burger menu in the navbar to enable Classic Mode on a specific session/device \n" +"The toggle is not visible while Persistent Classic Theme is enabled" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users +msgid "User" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users_settings +msgid "User Settings" +msgstr "" diff --git a/web_theme_classic/i18n/it.po b/web_theme_classic/i18n/it.po new file mode 100644 index 000000000000..17739385a8f7 --- /dev/null +++ b/web_theme_classic/i18n/it.po @@ -0,0 +1,62 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2026-04-30 09:36+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 5.15.2\n" + +#. module: web_theme_classic +#. odoo-javascript +#: code:addons/web_theme_classic/static/src/js/switch_theme.esm.js:0 +msgid "Classic Theme" +msgstr "Tema classico" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users__persistent_classic_theme +msgid "Classic Theme Persistent" +msgstr "Tema classico persistente" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_ir_http +msgid "HTTP Routing" +msgstr "Instradamento HTTP" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users_settings__persistent_classic_theme +msgid "Persistent Classic Theme" +msgstr "Tema classico persistente" + +#. module: web_theme_classic +#: model:ir.model.fields,help:web_theme_classic.field_res_users__persistent_classic_theme +msgid "" +"This enables Classic Theme on this user's account across all devices. \n" +" Disabling it will will alow you to to use the toggle in the user burger " +"menu in the navbar to enable Classic Mode on a specific session/device \n" +"The toggle is not visible while Persistent Classic Theme is enabled" +msgstr "" +"Questa opzione abilita il tema classico sull'account di questo utente su " +"tutti i dispositivi.\n" +"Disabilitandola, si potrà utilizzare l'interruttore nel pulsante menu " +"dell'utente nella barra di navigazione per abilitare la modalità classica su " +"una sessione/dispositivo specifici.\n" +"L'interruttore non è visibile quando il tema classico persistente è abilitato" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users +msgid "User" +msgstr "Utente" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users_settings +msgid "User Settings" +msgstr "Impostazioni utente" diff --git a/web_theme_classic/i18n/tr.po b/web_theme_classic/i18n/tr.po new file mode 100644 index 000000000000..d14f93f284ac --- /dev/null +++ b/web_theme_classic/i18n/tr.po @@ -0,0 +1,54 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: tr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" + +#. module: web_theme_classic +#. odoo-javascript +#: code:addons/web_theme_classic/static/src/js/switch_theme.esm.js:0 +msgid "Classic Theme" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users__persistent_classic_theme +msgid "Classic Theme Persistent" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_ir_http +msgid "HTTP Routing" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users_settings__persistent_classic_theme +msgid "Persistent Classic Theme" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,help:web_theme_classic.field_res_users__persistent_classic_theme +msgid "" +"This enables Classic Theme on this user's account across all devices. \n" +" Disabling it will will alow you to to use the toggle in the user burger " +"menu in the navbar to enable Classic Mode on a specific session/device \n" +"The toggle is not visible while Persistent Classic Theme is enabled" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users +msgid "User" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users_settings +msgid "User Settings" +msgstr "" diff --git a/web_theme_classic/i18n/web_theme_classic.pot b/web_theme_classic/i18n/web_theme_classic.pot new file mode 100644 index 000000000000..ea3c52ebf70f --- /dev/null +++ b/web_theme_classic/i18n/web_theme_classic.pot @@ -0,0 +1,53 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * web_theme_classic +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: web_theme_classic +#. odoo-javascript +#: code:addons/web_theme_classic/static/src/js/switch_theme.esm.js:0 +msgid "Classic Theme" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users__persistent_classic_theme +msgid "Classic Theme Persistent" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_ir_http +msgid "HTTP Routing" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,field_description:web_theme_classic.field_res_users_settings__persistent_classic_theme +msgid "Persistent Classic Theme" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model.fields,help:web_theme_classic.field_res_users__persistent_classic_theme +msgid "" +"This enables Classic Theme on this user's account across all devices. \n" +" Disabling it will will alow you to to use the toggle in the user burger menu in the navbar to enable Classic Mode on a specific session/device \n" +"The toggle is not visible while Persistent Classic Theme is enabled" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users +msgid "User" +msgstr "" + +#. module: web_theme_classic +#: model:ir.model,name:web_theme_classic.model_res_users_settings +msgid "User Settings" +msgstr "" diff --git a/web_theme_classic/models/__init__.py b/web_theme_classic/models/__init__.py new file mode 100644 index 000000000000..604d2da2838e --- /dev/null +++ b/web_theme_classic/models/__init__.py @@ -0,0 +1 @@ +from . import ir_http, res_users, res_users_settings diff --git a/web_theme_classic/models/ir_http.py b/web_theme_classic/models/ir_http.py new file mode 100644 index 000000000000..57c4b72eb901 --- /dev/null +++ b/web_theme_classic/models/ir_http.py @@ -0,0 +1,28 @@ +# © 2022 Florian Kantelberg - initOS GmbH +# © 2025 Liam Noonan - Pyxiris +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models +from odoo.http import request + + +class IrHttp(models.AbstractModel): + _inherit = "ir.http" + + @classmethod + def _set_classic_theme(cls, response): + user = request.env.user + if user and user._is_internal(): + existing_transient_theme = request.httprequest.cookies.get( + "transient_classic_theme_cookie" + ) + persistent_theme = getattr(user, "persistent_classic_theme", None) + # Delete the cookie so that when persistent gets turned off the user + # will not be left wondering why nothing changed + if persistent_theme and existing_transient_theme: + response.delete_cookie("transient_classic_theme_cookie") + + @classmethod + def _post_dispatch(cls, response): + cls._set_classic_theme(response) + return super()._post_dispatch(response) diff --git a/web_theme_classic/models/res_users.py b/web_theme_classic/models/res_users.py new file mode 100644 index 000000000000..f6c4683e4c58 --- /dev/null +++ b/web_theme_classic/models/res_users.py @@ -0,0 +1,31 @@ +# © 2022 Florian Kantelberg - initOS GmbH +# © 2025 Liam Noonan - Pyxiris +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + persistent_classic_theme = fields.Boolean( + related="res_users_settings_id.persistent_classic_theme", + readonly=False, + string="Classic Theme Persistent", + help="This enables Classic Theme on this user's account across all devices. \n " + "Disabling it will will alow you to to use the toggle in the user burger menu " + "in the navbar to enable Classic Mode on a specific session/device \n" + "The toggle is not visible while Persistent Classic Theme is enabled", + ) + + @property + def SELF_READABLE_FIELDS(self): + return super().SELF_READABLE_FIELDS + [ + "persistent_classic_theme", + ] + + @property + def SELF_WRITEABLE_FIELDS(self): + return super().SELF_WRITEABLE_FIELDS + [ + "persistent_classic_theme", + ] diff --git a/web_theme_classic/models/res_users_settings.py b/web_theme_classic/models/res_users_settings.py new file mode 100644 index 000000000000..99b5fe33fdf0 --- /dev/null +++ b/web_theme_classic/models/res_users_settings.py @@ -0,0 +1,12 @@ +# © 2026 Liam Noonan - Pyxiris +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResUsersSettings(models.Model): + _inherit = "res.users.settings" + + # These fields should be here in order to be accessible via in js + # as user.settings.persistent_classic_theme + persistent_classic_theme = fields.Boolean(default=True) diff --git a/web_theme_classic/pyproject.toml b/web_theme_classic/pyproject.toml new file mode 100644 index 000000000000..4231d0cccb3d --- /dev/null +++ b/web_theme_classic/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/web_theme_classic/readme/CONFIGURE.md b/web_theme_classic/readme/CONFIGURE.md new file mode 100644 index 000000000000..2824ab8c8952 --- /dev/null +++ b/web_theme_classic/readme/CONFIGURE.md @@ -0,0 +1,7 @@ +This module allows each user to choose whether they would like input fields to be displayed the "classic" way or the new, standard way (as if this module were not installed) + +To do this you can either: ++ Check "Classic Theme Persistent" in user preferences. This will enable the classic theme for that user across all devices. ++ Check the "Classic Theme" toggle in the popover menu triggered bu clicking on the user icon in the navbar. This toggle is only visible when "Classic Theme Persistent" is disabled. + +Please note that when disabling "Classic Theme Persistent" the style will not change until the page is reloaded. diff --git a/web_theme_classic/readme/CONTRIBUTORS.md b/web_theme_classic/readme/CONTRIBUTORS.md new file mode 100644 index 000000000000..8ed90851b587 --- /dev/null +++ b/web_theme_classic/readme/CONTRIBUTORS.md @@ -0,0 +1,3 @@ +- Sylvain LE GAL () +- [Pyxiris](https://github.com/Pyxiris) + - [Liam Noonan](https://github.com/ljmnoonan) diff --git a/web_theme_classic/readme/DESCRIPTION.md b/web_theme_classic/readme/DESCRIPTION.md new file mode 100644 index 000000000000..289a33630b07 --- /dev/null +++ b/web_theme_classic/readme/DESCRIPTION.md @@ -0,0 +1,21 @@ +This module extends the Odoo Community Edition `web` module to improve +the visibility of input fields. + +**Rational:** Since Odoo V17, the design is very pure. That's great, but +it generates some problem for users : + +- Fields are not identifiable. (we can not know exactly + where they are until you hover over them with the cursor) +- There is no indication for the required fields until trying to save + (or exit the screen) + +In a way, this module restores the form display of version 15, but +preserving the "save on the fly" new feature. + +**Without this module** + +![](../static/description/product_template_form_without_module.png) + +**With this module** + +![](../static/description/product_template_form_with_module.png) diff --git a/web_theme_classic/static/description/icon.png b/web_theme_classic/static/description/icon.png new file mode 100644 index 000000000000..3a0328b516c4 Binary files /dev/null and b/web_theme_classic/static/description/icon.png differ diff --git a/web_theme_classic/static/description/index.html b/web_theme_classic/static/description/index.html new file mode 100644 index 000000000000..190aa5109dc1 --- /dev/null +++ b/web_theme_classic/static/description/index.html @@ -0,0 +1,467 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Web Theme Classic

+ +

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runboat

+

This module extends the Odoo Community Edition web module to improve +the visibility of input fields.

+

Rational: Since Odoo V17, the design is very pure. That’s great, but +it generates some problem for users :

+
    +
  • Fields are not identifiable. (we can not know exactly where they are +until you hover over them with the cursor)
  • +
  • There is no indication for the required fields until trying to save +(or exit the screen)
  • +
+

In a way, this module restores the form display of version 15, but +preserving the “save on the fly” new feature.

+

Without this module

+

image1

+

With this module

+

image2

+

Table of contents

+ +
+

Configuration

+

This module allows each user to choose whether they would like input +fields to be displayed the “classic” way or the new, standard way (as if +this module were not installed)

+

To do this you can either:

+
    +
  • Check “Classic Theme Persistent” in user preferences. This will enable +the classic theme for that user across all devices.
  • +
  • Check the “Classic Theme” toggle in the popover menu triggered bu +clicking on the user icon in the navbar. This toggle is only visible +when “Classic Theme Persistent” is disabled.
  • +
+

Please note that when disabling “Classic Theme Persistent” the style +will not change until the page is reloaded.

+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • GRAP
  • +
+
+ +
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

Current maintainer:

+

legalsylvain

+

This module is part of the OCA/web project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+
+ + diff --git a/web_theme_classic/static/description/product_template_form_with_module.png b/web_theme_classic/static/description/product_template_form_with_module.png new file mode 100644 index 000000000000..65302450a355 Binary files /dev/null and b/web_theme_classic/static/description/product_template_form_with_module.png differ diff --git a/web_theme_classic/static/description/product_template_form_without_module.png b/web_theme_classic/static/description/product_template_form_without_module.png new file mode 100644 index 000000000000..5e89d608e1d3 Binary files /dev/null and b/web_theme_classic/static/description/product_template_form_without_module.png differ diff --git a/web_theme_classic/static/src/js/switch_theme.esm.js b/web_theme_classic/static/src/js/switch_theme.esm.js new file mode 100644 index 000000000000..7efb15160017 --- /dev/null +++ b/web_theme_classic/static/src/js/switch_theme.esm.js @@ -0,0 +1,62 @@ +// © 2022 Florian Kantelberg - initOS GmbH +// © 2025 Liam Noonan - Pyxiris +// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +import {_t} from "@web/core/l10n/translation"; +import {browser} from "@web/core/browser/browser"; +import {cookie} from "@web/core/browser/cookie"; +import {registry} from "@web/core/registry"; +import {user} from "@web/core/user"; + +/** + * @param {import("@web/env").OdooEnv} env + */ +function classicThemeSwitchItem(env) { + return { + type: "switch", + id: "classic_theme.switch", + description: _t("Classic Theme"), + callback: () => { + env.services.classic_theme.switchTheme(); + }, + isChecked: cookie.get("transient_classic_theme_cookie") === "classic", + sequence: 43, + }; +} + +export const classicThemeService = { + dependencies: ["ui"], + + start(env, {ui}) { + // Apply theme on load + if ( + cookie.get("transient_classic_theme_cookie") === "classic" || + user.settings.persistent_classic_theme + ) { + document.body.classList.add("classic-theme"); + } + + if (!user.settings.persistent_classic_theme) { + registry + .category("user_menuitems") + .add("classic_theme.switch", classicThemeSwitchItem); + } + + return { + async switchTheme() { + const newValue = + cookie.get("transient_classic_theme_cookie") === "classic" + ? "pure" + : "classic"; + cookie.set("transient_classic_theme_cookie", newValue); + document.body.classList.toggle("classic-theme", newValue === "classic"); + + // We do not actually need a reload, but it does get rid of some style glitches + ui.block(); + browser.location.reload(); + }, + }; + }, +}; + +registry.category("services").add("classic_theme", classicThemeService); diff --git a/web_theme_classic/static/src/scss/web_theme_classic.dark.scss b/web_theme_classic/static/src/scss/web_theme_classic.dark.scss new file mode 100644 index 000000000000..e867c23a3d57 --- /dev/null +++ b/web_theme_classic/static/src/scss/web_theme_classic.dark.scss @@ -0,0 +1,2 @@ +$wtc-input-border-color-focus: rgba($o-action, 0.5) !default; +$wtc-input-background-color-required: mix($o-action, transparent, 10) !default; diff --git a/web_theme_classic/static/src/scss/web_theme_classic.scss b/web_theme_classic/static/src/scss/web_theme_classic.scss new file mode 100644 index 000000000000..56b6ee42743c --- /dev/null +++ b/web_theme_classic/static/src/scss/web_theme_classic.scss @@ -0,0 +1,181 @@ +/*********************************************************** + Variables +************************************************************/ + +/* The wtc prefix keeps these from conflicting with bootstrap vars*/ +$wtc-input-border-color: $o-gray-500 !default; +$wtc-input-border-color-focus: $o-community-color !default; +$wtc-input-color-required: $o-gray-900 !default; +// Note, it is very important that this be a mix with transparent! The reason is that the normal $o-input-bg +// is transparent and so some styles are built assuming this. The most notable examples are monetary fields +// which are set up like this: +//
+//
+// +// +// 0.00 +// +// +// +//
+//
+// So a non transparent background on the element blocks off the display. so it is much better to immitate $o-input-invalid-bg +// https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/scss/primary_variables.scss#L170 +$wtc-input-background-color-required: mix(#0000ff, transparent, 10) !default; +$wtc-input-color-placeholder-required: #6c757d !default; + +/*********************************************************** + Handle Borders +************************************************************/ +// Only activate these styles when the classic-theme class is set on the body +body.classic-theme { + /* Odoo sets this without consideration for nesting, as occurs with custom properties. + * https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/fields/fields.scss#L36C1-L39C2 + * We fix that here. We also use our special toned down version of $o-action for full borders */ + .o_field_widget:focus-within { + &:has(.o_field_widget) { + @include print-variable(o-input-border-color, $wtc-input-border-color); + @include print-variable(o-caret-color, $input-color); + } + @include print-variable(o-input-border-color, $wtc-input-border-color-focus); + @include print-variable(o-caret-color, $wtc-input-border-color-focus); + } + + // https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/fields/fields.scss#L50C1-L65C2 + .o_input { + border: $input-border-width solid var(--o-input-border-color); + border-radius: 3px; + } + + // An odd case. The search input when adding a new user to an existing task from kanban + // https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/fields/many2many_tags_avatar/many2many_tags_avatar_field.scss#L62C9-L62C55 + .o_m2m_tags_avatar_field_popover .o-autocomplete .o-autocomplete--input.o_input { + border-width: $input-border-width; + padding-left: $o-input-padding-x; + } + + // All these selectors are probably not necessary, but just following: + // https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/fields/properties/properties_field.scss#L12C1-L45C2 + .o_field_properties, + .o_field_properties.o_field_invalid, + .o_property_field_popover { + .o_input:focus, + .dropdown:focus ~ .o_dropdown_button, + .dropdown:focus-within ~ .o_dropdown_button, + .o_input:focus ~ .o_datepicker_button, + .o_dropdown_button:focus { + @include print-variable( + o-input-border-color, + $wtc-input-border-color-focus + ); + * { + @include print-variable( + o-input-border-color, + $wtc-input-border-color-focus + ); + } + } + } + + // Give tag type custom properties input borders too. Note the code we are overriding + // https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/fields/properties/property_value.scss#L43C1-L46C2 + .o_field_property_many2many_value:not(.readonly), +// https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/fields/properties/property_tags.scss#L29C1-L32C2 +.o_field_property_tag:not(.readonly) { + border: $input-border-width solid var(--o-input-border-color); + border-radius: 3px; + } + + .o_form_view { + /* Odoo sets borders to transparent unless hovered or focused. We override this. + * https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/form/form_controller.scss#L202C1-L204C6 */ + &:not(.o_field_highlight) + .o_field_widget:not(.o_field_invalid):not(.o_field_highlight) + .o_input:not(:hover):not(:focus) { + --o-input-border-color: #{$wtc-input-border-color}; + } + + /* Monetary fields need some special help */ + .o_field_monetary { + /* Prevent having double border for monetary fields */ + span.o_input:has(~ input.o_input) { + border: $input-border-width solid transparent !important; + } + + /* Keep the monetary symbol away from the border when it is outside the border */ + /* For when the symbol is on the left side */ + span.o_input + span.opacity-0 { + margin-right: 3px; + } + /* For when the symbol is on the right side */ + span.o_input ~ span.opacity-0:not(span.o_input + span.opacity-0) { + margin-left: 3px; + } + } + } + + /*********************************************************** + Form View : Handle Background for required fields +************************************************************/ + + // https://github.com/odoo/odoo/blob/18.0/addons/web/static/src/views/fields/fields.scss#L31C1-L34C2 + .o_required_modifier { + @include print-variable( + o-input-background-color, + $wtc-input-background-color-required + ); + } + + /*********************************************************** + Tree View : Handle style for input fields +************************************************************/ + + // We override all lists, not just in forms + .o_list_renderer .o_data_row { + // Prevent item description from getting $wtc-input-background-color-required when row not in focus + &:not(.selected_row) .o_input { + background-color: initial; + } + &.o_selected_row > .o_data_cell { + &.o_required_modifier:not(.o_readonly_modifier), + &.o_invalid_cell:not(.o_readonly_modifier) { + /* Disable border bottom as the field has now a background */ + border-bottom: 0px; + } + > .o_field_widget { + // We have to manually reintroduce the input invalid styles + &.o_field_invalid:not(.o_readonly_modifier):not( + .o_invisible_modifier + ):has(.o_input) { + --o-input-background-color: #{$o-input-invalid-bg}; + .o_input { + --o-input-border-color: #{$o-danger}; + } + } + &:not(.o_readonly_modifier):not(.o_invisible_modifier) { + &.o_required_modifier:not(.o_field_invalid) { + .o_input { + color: $wtc-input-color-required; + --o-input-background-color: #{$wtc-input-background-color-required} !important; + background-color: var( + --o-input-background-color + ) !important; + } + } + // Handle borders + .o_input { + border: $input-border-width solid var(--o-input-border-color) !important; + /* Prevent double borders in nested o_input like tags */ + .o_input { + border: 0 !important; + } + } + } + // Handle monetary fields in list + &.o_field_monetary span.o_input:has(~ input.o_input) { + border: $input-border-width solid transparent !important; + } + } + } + } +} diff --git a/web_theme_classic/tests/__init__.py b/web_theme_classic/tests/__init__.py new file mode 100644 index 000000000000..e2983aa2a489 --- /dev/null +++ b/web_theme_classic/tests/__init__.py @@ -0,0 +1 @@ +from . import test_ir_http diff --git a/web_theme_classic/tests/test_ir_http.py b/web_theme_classic/tests/test_ir_http.py new file mode 100644 index 000000000000..3b8db3adc904 --- /dev/null +++ b/web_theme_classic/tests/test_ir_http.py @@ -0,0 +1,91 @@ +# © 2022 Florian Kantelberg - initOS GmbH +# © 2026 Liam Noonan - Pyxiris +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo.tests import HttpCase, new_test_user, tagged + +HOST = "127.0.0.1" + + +@tagged("post_install", "-at_install") +class TestClassicTheme(HttpCase): + def setUp(self): + super().setUp() + self.test_portal_user = new_test_user( + self.env, "test_portal_user", groups="base.group_portal" + ) + # new_test_user() does not create a res_users_settings table for portal users + # for some reason, even though in an actual db this exists. We forcibly make + # it here so we can test that our logic does not run for portal users + self.env["res.users.settings"].create( + {"user_id": self.test_portal_user.id, "persistent_classic_theme": True} + ) + + self.test_internal_user = new_test_user( + self.env, "test_internal_user", groups="base.group_user" + ) + self.test_internal_user.write({"persistent_classic_theme": False}) + + # Non internal user -> skip logic, do nothing + def test_01_non_internal_user_ignored(self): + self.authenticate(self.test_portal_user.login, self.test_portal_user.login) + self.opener.cookies.set( + "transient_classic_theme_cookie", "pure", domain=HOST, path="/" + ) + response = self.url_open("/my") + cookie_header = response.headers.get("Set-Cookie", "") + self.assertNotIn( + "transient_classic_theme_cookie", + cookie_header, + "We should have skipped over this due to being an external user", + ) + + # Persistent theme not set, no cookie -> do nothing + def test_02_persistent_theme_not_set_no_cookie(self): + self.authenticate(self.test_internal_user.login, self.test_internal_user.login) + response = self.url_open("/odoo") + cookie_header = response.headers.get("Set-Cookie", "") + self.assertNotIn( + "transient_classic_theme_cookie", + cookie_header, + "Persistent is not set and there was no cookie, " + "so we should not be deleting the cookie", + ) + + # Persistent theme not set, cookie exists -> do nothing + def test_03_persistent_theme_not_set_cookie_exists(self): + self.authenticate(self.test_internal_user.login, self.test_internal_user.login) + self.opener.cookies.set( + "transient_classic_theme_cookie", "classic", domain=HOST, path="/" + ) + response = self.url_open("/odoo") + cookie_header = response.headers.get("Set-Cookie", "") + self.assertNotIn( + "transient_classic_theme_cookie", + cookie_header, + "Persistent is not set, so we should not be deleting the cookie", + ) + + # Persistent theme set, no cookie -> do nothing + def test_04_persistent_theme_set_no_cookie(self): + self.test_internal_user.write({"persistent_classic_theme": True}) + self.authenticate(self.test_internal_user.login, self.test_internal_user.login) + response = self.url_open("/odoo") + cookie_header = response.headers.get("Set-Cookie", "") + self.assertNotIn( + "transient_classic_theme_cookie", + cookie_header, + "Persistent is set but there was no cookie, " + "so we should not be deleting the cookie", + ) + + # Persistent theme set, cookie exists -> delete cookie + def test_05_persistent_theme_set_cookie_exists(self): + self.test_internal_user.write({"persistent_classic_theme": True}) + self.authenticate(self.test_internal_user.login, self.test_internal_user.login) + self.opener.cookies.set( + "transient_classic_theme_cookie", "classic", domain=HOST, path="/" + ) + response = self.url_open("/odoo") + cookie_header = response.headers.get("Set-Cookie", "") + self.assertIn("transient_classic_theme_cookie", cookie_header) diff --git a/web_theme_classic/views/res_users_views.xml b/web_theme_classic/views/res_users_views.xml new file mode 100644 index 000000000000..e9f87f28c557 --- /dev/null +++ b/web_theme_classic/views/res_users_views.xml @@ -0,0 +1,25 @@ + + + + res.users + + + + + + + + + + + + res.users.form.web_theme_classic + res.users + + + + + + + +