From bcc67c153dba848271ea873fe84cd74535eb8469 Mon Sep 17 00:00:00 2001 From: Antonio David Ruban Date: Fri, 6 Nov 2026 01:36:49 -0400 Subject: [PATCH] [FIX] barcode_scanner: notify errors as danger BarcodeScannerFeedbackService forwarded the feedback level directly as the notification type. Odoo expects "danger" for error notifications, so "error" was not rendered as a danger notification. Map feedback levels to valid Odoo notification types and add a regression test covering all levels. --- .../src/js/services/feedback_service.esm.js | 11 +++++- .../static/tests/feedback_service.test.js | 39 +++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 barcode_scanner/static/tests/feedback_service.test.js diff --git a/barcode_scanner/static/src/js/services/feedback_service.esm.js b/barcode_scanner/static/src/js/services/feedback_service.esm.js index ee97a88..7ab5bec 100644 --- a/barcode_scanner/static/src/js/services/feedback_service.esm.js +++ b/barcode_scanner/static/src/js/services/feedback_service.esm.js @@ -1,6 +1,13 @@ import {Reactive} from "@web/core/utils/reactive"; import {registry} from "@web/core/registry"; +const NOTIFICATION_TYPES = { + success: "success", + warning: "warning", + error: "danger", + info: "info", +}; + const DEFAULT_PROFILES = { success: { vibration: [35], @@ -83,7 +90,9 @@ export class BarcodeScannerFeedbackService extends Reactive { const signal = {level, message: options.message || "", at: Date.now()}; this.lastSignal = signal; if (options.notify && options.message) { - this.notification.add(options.message, {type: level}); + this.notification.add(options.message, { + type: NOTIFICATION_TYPES[level] || "info", + }); } if (this.enabled.flash) { this.flashOnce(level, options.flashDurationMs || 180); diff --git a/barcode_scanner/static/tests/feedback_service.test.js b/barcode_scanner/static/tests/feedback_service.test.js new file mode 100644 index 0000000..0923842 --- /dev/null +++ b/barcode_scanner/static/tests/feedback_service.test.js @@ -0,0 +1,39 @@ +import {describe, expect, test} from "@odoo/hoot"; +import {BarcodeScannerFeedbackService} from "@barcode_scanner/js/services/feedback_service.esm"; + +function makeFeedback(notifications) { + const feedback = new BarcodeScannerFeedbackService({ + add: (...args) => notifications.push(args), + }); + feedback.enabled = {audio: false, vibration: false, flash: false}; + return feedback; +} + +describe("BarcodeScannerFeedbackService", () => { + test("error feedback uses the danger notification type", () => { + const notifications = []; + const feedback = makeFeedback(notifications); + const message = "Unable to apply the cycle count"; + + feedback.error({message, notify: true}); + + expect(notifications).toEqual([[message, {type: "danger"}]]); + feedback.destroy(); + }); + + test("feedback levels map to valid Odoo notification types", () => { + const cases = [ + ["success", "success"], + ["warning", "warning"], + ["info", "info"], + ["error", "danger"], + ]; + for (const [level, type] of cases) { + const notifications = []; + const feedback = makeFeedback(notifications); + feedback[level]({message: level, notify: true}); + expect(notifications).toEqual([[level, {type}]]); + feedback.destroy(); + } + }); +});