From 323da02cf15c568ec8a439e37ec49236307dae7a Mon Sep 17 00:00:00 2001 From: Andreu Orensanz Date: Fri, 20 Mar 2026 10:40:46 +0100 Subject: [PATCH] [ADD] mail_notification_volume --- mail_notification_volume/README.rst | 86 ++++ mail_notification_volume/__init__.py | 4 + mail_notification_volume/__manifest__.py | 25 + mail_notification_volume/models/__init__.py | 5 + mail_notification_volume/models/res_users.py | 21 + .../models/res_users_settings.py | 10 + mail_notification_volume/pyproject.toml | 3 + .../readme/CONTRIBUTORS.md | 1 + .../readme/DESCRIPTION.md | 7 + .../static/description/index.html | 433 ++++++++++++++++++ .../src/out_of_focus_service_patch.esm.js | 29 ++ .../src/user_settings_service_patch.esm.js | 37 ++ .../static/src/volume_slider_field.esm.js | 52 +++ .../static/src/volume_slider_field.xml | 36 ++ .../views/res_users_views.xml | 13 + 15 files changed, 762 insertions(+) create mode 100644 mail_notification_volume/README.rst create mode 100644 mail_notification_volume/__init__.py create mode 100644 mail_notification_volume/__manifest__.py create mode 100644 mail_notification_volume/models/__init__.py create mode 100644 mail_notification_volume/models/res_users.py create mode 100644 mail_notification_volume/models/res_users_settings.py create mode 100644 mail_notification_volume/pyproject.toml create mode 100644 mail_notification_volume/readme/CONTRIBUTORS.md create mode 100644 mail_notification_volume/readme/DESCRIPTION.md create mode 100644 mail_notification_volume/static/description/index.html create mode 100644 mail_notification_volume/static/src/out_of_focus_service_patch.esm.js create mode 100644 mail_notification_volume/static/src/user_settings_service_patch.esm.js create mode 100644 mail_notification_volume/static/src/volume_slider_field.esm.js create mode 100644 mail_notification_volume/static/src/volume_slider_field.xml create mode 100644 mail_notification_volume/views/res_users_views.xml diff --git a/mail_notification_volume/README.rst b/mail_notification_volume/README.rst new file mode 100644 index 000000000..b8bf96381 --- /dev/null +++ b/mail_notification_volume/README.rst @@ -0,0 +1,86 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================== +Mail Notification Volume +======================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ab1c573b36a2409ccc53006da4f23f5f07610f44cfa0ff23937f8c50f7095dfe + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fmail-lightgray.png?logo=github + :target: https://github.com/OCA/mail/tree/17.0/mail_notification_volume + :alt: OCA/mail +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/mail-17-0/mail-17-0-mail_notification_volume + :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/mail&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows users to configure the volume of notification sounds +in Odoo (chat messages, inbox notifications, etc.). + +A volume slider is added to the user's Preferences page, with a test +button to preview the sound at the selected volume. + +By default, the volume is set to 100%. + +**Table of contents** + +.. contents:: + :local: + +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 +------- + +* ForgeFlow + +Contributors +------------ + +- Andreu Orensanz + +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. + +This module is part of the `OCA/mail `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mail_notification_volume/__init__.py b/mail_notification_volume/__init__.py new file mode 100644 index 000000000..62c7e3b07 --- /dev/null +++ b/mail_notification_volume/__init__.py @@ -0,0 +1,4 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/mail_notification_volume/__manifest__.py b/mail_notification_volume/__manifest__.py new file mode 100644 index 000000000..3f2012315 --- /dev/null +++ b/mail_notification_volume/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Mail Notification Volume", + "summary": "Allow users to configure notification sound volume", + "version": "17.0.1.0.0", + "development_status": "Beta", + "category": "Social Network", + "website": "https://github.com/OCA/mail", + "author": "ForgeFlow, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["mail"], + "data": [ + "views/res_users_views.xml", + ], + "assets": { + "web.assets_backend": [ + "mail_notification_volume/static/src/user_settings_service_patch.js", + "mail_notification_volume/static/src/out_of_focus_service_patch.js", + "mail_notification_volume/static/src/volume_slider_field.js", + "mail_notification_volume/static/src/volume_slider_field.xml", + ], + }, +} diff --git a/mail_notification_volume/models/__init__.py b/mail_notification_volume/models/__init__.py new file mode 100644 index 000000000..587fee466 --- /dev/null +++ b/mail_notification_volume/models/__init__.py @@ -0,0 +1,5 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import res_users +from . import res_users_settings diff --git a/mail_notification_volume/models/res_users.py b/mail_notification_volume/models/res_users.py new file mode 100644 index 000000000..900bc0021 --- /dev/null +++ b/mail_notification_volume/models/res_users.py @@ -0,0 +1,21 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResUsers(models.Model): + _inherit = "res.users" + + notification_volume = fields.Float( + related="res_users_settings_id.notification_volume", + readonly=False, + ) + + @property + def SELF_READABLE_FIELDS(self): + return super().SELF_READABLE_FIELDS + ["notification_volume"] + + @property + def SELF_WRITEABLE_FIELDS(self): + return super().SELF_WRITEABLE_FIELDS + ["notification_volume"] diff --git a/mail_notification_volume/models/res_users_settings.py b/mail_notification_volume/models/res_users_settings.py new file mode 100644 index 000000000..376c65ad6 --- /dev/null +++ b/mail_notification_volume/models/res_users_settings.py @@ -0,0 +1,10 @@ +# Copyright 2026 ForgeFlow S.L. (https://www.forgeflow.com) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class ResUsersSettings(models.Model): + _inherit = "res.users.settings" + + notification_volume = fields.Float(default=1.0) diff --git a/mail_notification_volume/pyproject.toml b/mail_notification_volume/pyproject.toml new file mode 100644 index 000000000..4231d0ccc --- /dev/null +++ b/mail_notification_volume/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/mail_notification_volume/readme/CONTRIBUTORS.md b/mail_notification_volume/readme/CONTRIBUTORS.md new file mode 100644 index 000000000..3c48b3419 --- /dev/null +++ b/mail_notification_volume/readme/CONTRIBUTORS.md @@ -0,0 +1 @@ +- Andreu Orensanz \ diff --git a/mail_notification_volume/readme/DESCRIPTION.md b/mail_notification_volume/readme/DESCRIPTION.md new file mode 100644 index 000000000..89f5cf2ba --- /dev/null +++ b/mail_notification_volume/readme/DESCRIPTION.md @@ -0,0 +1,7 @@ +This module allows users to configure the volume of notification sounds +in Odoo (chat messages, inbox notifications, etc.). + +A volume slider is added to the user's Preferences page, with a test +button to preview the sound at the selected volume. + +By default, the volume is set to 100%. diff --git a/mail_notification_volume/static/description/index.html b/mail_notification_volume/static/description/index.html new file mode 100644 index 000000000..b7af985f7 --- /dev/null +++ b/mail_notification_volume/static/description/index.html @@ -0,0 +1,433 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Mail Notification Volume

+ +

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

+

This module allows users to configure the volume of notification sounds +in Odoo (chat messages, inbox notifications, etc.).

+

A volume slider is added to the user’s Preferences page, with a test +button to preview the sound at the selected volume.

+

By default, the volume is set to 100%.

+

Table of contents

+ +
+

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

+
    +
  • ForgeFlow
  • +
+
+
+

Contributors

+ +
+
+

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.

+

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

+

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

+
+
+
+
+ + diff --git a/mail_notification_volume/static/src/out_of_focus_service_patch.esm.js b/mail_notification_volume/static/src/out_of_focus_service_patch.esm.js new file mode 100644 index 000000000..9d7c93307 --- /dev/null +++ b/mail_notification_volume/static/src/out_of_focus_service_patch.esm.js @@ -0,0 +1,29 @@ +/** @odoo-module */ + +import {OutOfFocusService} from "@mail/core/common/out_of_focus_service"; +import {patch} from "@web/core/utils/patch"; +import {url} from "@web/core/utils/urls"; + +patch(OutOfFocusService.prototype, { + async _playSound() { + if (this.canPlayAudio && this.multiTab.isOnMainTab()) { + if (!this.audio) { + this.audio = new Audio(); + this.audio.src = this.audio.canPlayType("audio/ogg; codecs=vorbis") + ? url("/mail/static/src/audio/ting.ogg") + : url("/mail/static/src/audio/ting.mp3"); + } + const userSettings = this.env.services["mail.user_settings"]; + this.audio.volume = + userSettings && userSettings.notificationVolume !== undefined + ? userSettings.notificationVolume + : 0.7; + try { + await this.audio.play(); + } catch { + // Ignore errors due to the user not having interacted + // with the page before playing the sound. + } + } + }, +}); diff --git a/mail_notification_volume/static/src/user_settings_service_patch.esm.js b/mail_notification_volume/static/src/user_settings_service_patch.esm.js new file mode 100644 index 000000000..e82cb4da7 --- /dev/null +++ b/mail_notification_volume/static/src/user_settings_service_patch.esm.js @@ -0,0 +1,37 @@ +/** @odoo-module */ + +import {UserSettings} from "@mail/core/common/user_settings_service"; +import {patch} from "@web/core/utils/patch"; + +patch(UserSettings.prototype, { + notificationVolume: 0.7, + + updateFromCommands(settings) { + super.updateFromCommands(settings); + if ("notification_volume" in settings) { + this.notificationVolume = settings.notification_volume; + } + }, + + setNotificationVolume(value) { + this.notificationVolume = parseFloat(value); + this._saveSettings(); + }, + + async _onSaveGlobalSettingsTimeout() { + this.globalSettingsTimeout = undefined; + await this.orm.call( + "res.users.settings", + "set_res_users_settings", + [[this.id]], + { + new_settings: { + push_to_talk_key: this.pushToTalkKey, + use_push_to_talk: this.usePushToTalk, + voice_active_duration: this.voiceActiveDuration, + notification_volume: this.notificationVolume, + }, + } + ); + }, +}); diff --git a/mail_notification_volume/static/src/volume_slider_field.esm.js b/mail_notification_volume/static/src/volume_slider_field.esm.js new file mode 100644 index 000000000..c367a935f --- /dev/null +++ b/mail_notification_volume/static/src/volume_slider_field.esm.js @@ -0,0 +1,52 @@ +/** @odoo-module */ + +import {Component} from "@odoo/owl"; +import {_t} from "@web/core/l10n/translation"; +import {registry} from "@web/core/registry"; +import {standardFieldProps} from "@web/views/fields/standard_field_props"; +import {url} from "@web/core/utils/urls"; + +export class VolumeSliderField extends Component { + static template = "mail_notification_volume.VolumeSliderField"; + static props = { + ...standardFieldProps, + }; + + setup() { + this.testAudio = null; + } + + get value() { + return this.props.record.data[this.props.name] || 0; + } + + get percentage() { + return Math.round(this.value * 100); + } + + onChange(ev) { + this.props.record.update({[this.props.name]: parseFloat(ev.target.value)}); + } + + onTestSound() { + if (!this.testAudio) { + this.testAudio = new Audio(); + this.testAudio.src = this.testAudio.canPlayType("audio/ogg; codecs=vorbis") + ? url("/mail/static/src/audio/ting.ogg") + : url("/mail/static/src/audio/ting.mp3"); + } + this.testAudio.volume = this.value; + this.testAudio.currentTime = 0; + this.testAudio.play().catch(() => { + // Ignore autoplay errors + }); + } +} + +export const volumeSliderField = { + component: VolumeSliderField, + displayName: _t("Volume Slider"), + supportedTypes: ["float"], +}; + +registry.category("fields").add("volume_slider", volumeSliderField); diff --git a/mail_notification_volume/static/src/volume_slider_field.xml b/mail_notification_volume/static/src/volume_slider_field.xml new file mode 100644 index 000000000..4df891397 --- /dev/null +++ b/mail_notification_volume/static/src/volume_slider_field.xml @@ -0,0 +1,36 @@ + + + + + + + + +
+ + +
+
+
+ +
diff --git a/mail_notification_volume/views/res_users_views.xml b/mail_notification_volume/views/res_users_views.xml new file mode 100644 index 000000000..fadbb4e19 --- /dev/null +++ b/mail_notification_volume/views/res_users_views.xml @@ -0,0 +1,13 @@ + + + + res.users.preferences.form.notification.volume + res.users + + + + + + + +