From 94c340c88ed46adf1fbf561751944542d8838e7c Mon Sep 17 00:00:00 2001 From: Zuzanna Elzbieta Szalaty Szalaty Date: Wed, 9 Sep 2026 09:32:56 +0100 Subject: [PATCH] [ADD] barcode_scanner: scanner-first Barcode app core --- barcode_scanner/README.rst | 169 + barcode_scanner/__init__.py | 3 + barcode_scanner/__manifest__.py | 44 + barcode_scanner/i18n/es.po | 59 + barcode_scanner/pyproject.toml | 3 + barcode_scanner/readme/CONTRIBUTORS.md | 2 + barcode_scanner/readme/DESCRIPTION.md | 14 + barcode_scanner/readme/USAGE.md | 59 + barcode_scanner/static/description/icon.png | Bin 0 -> 9455 bytes barcode_scanner/static/description/index.html | 500 +++ .../static/src/img/icon_barcode.svg | 65 + barcode_scanner/static/src/js/api.esm.js | 133 + barcode_scanner/static/src/js/app.esm.js | 66 + barcode_scanner/static/src/js/barcode.esm.js | 408 ++ .../static/src/js/barcode_parser.esm.js | 29 + .../static/src/js/hooks/use_barcode.esm.js | 26 + .../js/hooks/use_barcode_dispatcher.esm.js | 34 + .../src/js/hooks/use_barcode_handler.esm.js | 10 + .../static/src/js/hooks/use_inventory.esm.js | 17 + .../static/src/js/registries.esm.js | 28 + barcode_scanner/static/src/js/router.esm.js | 129 + .../static/src/js/screens/main_screen.esm.js | 71 + .../src/js/services/feedback_service.esm.js | 157 + barcode_scanner/static/src/js/store.esm.js | 12 + .../static/src/js/utils/scan_match.esm.js | 53 + .../static/src/scss/barcode_scanner.scss | 3720 +++++++++++++++++ .../src/xml/barcode_scanner_templates.xml | 66 + .../static/tests/api_error_message.test.js | 63 + barcode_scanner/tests/__init__.py | 1 + barcode_scanner/tests/test_js.py | 23 + barcode_scanner/views/action.xml | 13 + barcode_scanner/views/templates.xml | 10 + 32 files changed, 5987 insertions(+) create mode 100644 barcode_scanner/README.rst create mode 100644 barcode_scanner/__init__.py create mode 100644 barcode_scanner/__manifest__.py create mode 100644 barcode_scanner/i18n/es.po create mode 100644 barcode_scanner/pyproject.toml create mode 100644 barcode_scanner/readme/CONTRIBUTORS.md create mode 100644 barcode_scanner/readme/DESCRIPTION.md create mode 100644 barcode_scanner/readme/USAGE.md create mode 100644 barcode_scanner/static/description/icon.png create mode 100644 barcode_scanner/static/description/index.html create mode 100644 barcode_scanner/static/src/img/icon_barcode.svg create mode 100644 barcode_scanner/static/src/js/api.esm.js create mode 100644 barcode_scanner/static/src/js/app.esm.js create mode 100644 barcode_scanner/static/src/js/barcode.esm.js create mode 100644 barcode_scanner/static/src/js/barcode_parser.esm.js create mode 100644 barcode_scanner/static/src/js/hooks/use_barcode.esm.js create mode 100644 barcode_scanner/static/src/js/hooks/use_barcode_dispatcher.esm.js create mode 100644 barcode_scanner/static/src/js/hooks/use_barcode_handler.esm.js create mode 100644 barcode_scanner/static/src/js/hooks/use_inventory.esm.js create mode 100644 barcode_scanner/static/src/js/registries.esm.js create mode 100644 barcode_scanner/static/src/js/router.esm.js create mode 100644 barcode_scanner/static/src/js/screens/main_screen.esm.js create mode 100644 barcode_scanner/static/src/js/services/feedback_service.esm.js create mode 100644 barcode_scanner/static/src/js/store.esm.js create mode 100644 barcode_scanner/static/src/js/utils/scan_match.esm.js create mode 100644 barcode_scanner/static/src/scss/barcode_scanner.scss create mode 100644 barcode_scanner/static/src/xml/barcode_scanner_templates.xml create mode 100644 barcode_scanner/static/tests/api_error_message.test.js create mode 100644 barcode_scanner/tests/__init__.py create mode 100644 barcode_scanner/tests/test_js.py create mode 100644 barcode_scanner/views/action.xml create mode 100644 barcode_scanner/views/templates.xml diff --git a/barcode_scanner/README.rst b/barcode_scanner/README.rst new file mode 100644 index 0000000..6db1637 --- /dev/null +++ b/barcode_scanner/README.rst @@ -0,0 +1,169 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +=============== +Barcode Scanner +=============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ba6365d70b631c205696ddd617c9738e11ae52e29ec43c03f6394bdd7815d1a8 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fbarcode--interface-lightgray.png?logo=github + :target: https://github.com/OCA/barcode-interface/tree/18.0/barcode_scanner + :alt: OCA/barcode-interface +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/barcode-interface-18-0/barcode-interface-18-0-barcode_scanner + :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/barcode-interface&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is the **base framework** of the Barcode suite: a fast, +full-screen scanning application shell for Odoo that other modules +extend. + +It ships no business logic of its own. Instead it exposes the building +blocks feature modules plug into, the same way Odoo widgets +self-register: + +- a full-screen client action and a lightweight in-app router; +- registries for screens, scan handlers and home-screen menu tiles + (``barcode_screens``, ``barcode_scan_handlers``, + ``barcode_menu_tiles``); +- the barcode input service (hardware/keyboard wedge), audio/vibration + feedback, an ORM/API wrapper and shared hooks. + +Install a feature module on top — such as ``barcode_stock`` — to get +actual warehouse operations. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +``barcode_scanner`` is a framework and is not useful on its own: install +a feature module such as ``barcode_stock`` to get actual operations. + +To build your own feature module, register your pieces into the +framework registries — no change to the base module is required. + +Register a screen: + +.. code:: js + + import {barcodeScreens} from "@barcode_scanner/js/registries"; + + barcodeScreens.add("my_screen", {component: MyScreen}); + +Register a scan handler (tried in ``sequence`` order; the first that +returns a truthy value consumes the scan): + +.. code:: js + + import {barcodeScanHandlers} from "@barcode_scanner/js/registries"; + + barcodeScanHandlers.add("my_handler", { + async handle(barcode, parsed, {api, navigate, notify}) { + // return true when handled + }, + }, {sequence: 50}); + +Register a home-screen tile: + +.. code:: js + + import {barcodeMenuTiles} from "@barcode_scanner/js/registries"; + + barcodeMenuTiles.add("my_tile", { + label: "My Screen", + icon: "fa-cube", + action: ({navigate}) => navigate("my_screen"), + }, {sequence: 50}); + +Register a barcode parser (tried in ``sequence`` order before the +built-in EAN13 one; return ``null`` to let the next parser try): + +.. code:: js + + import {barcodeParsers} from "@barcode_scanner/js/registries"; + + barcodeParsers.add("my_symbology", (barcode) => { + // return {type: "...", value: "", ...} or null + }, {sequence: 20}); + +Register a startup task, for data your module needs before the first +scan (``barcode_gs1`` reads its nomenclature this way). Tasks are +awaited when the app opens; one that fails is logged and skipped: + +.. code:: js + + import {barcodeStartupTasks} from "@barcode_scanner/js/registries"; + + barcodeStartupTasks.add("my_config", (env) => loadMyConfig(env.services.orm)); + +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 +------- + +* Binhex + +Contributors +------------ + +- `Antonio David Ruban Espinal `__ +- `Zuzanna Elzbieta Szalaty + Szalaty `__ + +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-szalatyzuzanna| image:: https://github.com/szalatyzuzanna.png?size=40px + :target: https://github.com/szalatyzuzanna + :alt: szalatyzuzanna + +Current `maintainer `__: + +|maintainer-szalatyzuzanna| + +This module is part of the `OCA/barcode-interface `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/barcode_scanner/__init__.py b/barcode_scanner/__init__.py new file mode 100644 index 0000000..406f3fc --- /dev/null +++ b/barcode_scanner/__init__.py @@ -0,0 +1,3 @@ +# The base barcode_scanner module ships no Python models; it is a pure +# JavaScript scanning framework. Feature modules (e.g. barcode_stock) add +# their own models. diff --git a/barcode_scanner/__manifest__.py b/barcode_scanner/__manifest__.py new file mode 100644 index 0000000..1905ac7 --- /dev/null +++ b/barcode_scanner/__manifest__.py @@ -0,0 +1,44 @@ +{ + "name": "Barcode Scanner", + "version": "18.0.1.0.0", + "category": "Hidden", + "summary": "Base scanning framework: client action, registries, scanner " + "input and hooks", + "author": "Binhex, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/barcode-interface", + "maintainers": ["szalatyzuzanna"], + "license": "AGPL-3", + "depends": [ + "web", + ], + "data": [ + "views/action.xml", + "views/templates.xml", + ], + "assets": { + "web.assets_backend": [ + "barcode_scanner/static/src/scss/barcode_scanner.scss", + "barcode_scanner/static/src/xml/barcode_scanner_templates.xml", + "barcode_scanner/static/src/js/registries.esm.js", + "barcode_scanner/static/src/js/barcode_parser.esm.js", + "barcode_scanner/static/src/js/utils/scan_match.esm.js", + "barcode_scanner/static/src/js/barcode.esm.js", + "barcode_scanner/static/src/js/api.esm.js", + "barcode_scanner/static/src/js/router.esm.js", + "barcode_scanner/static/src/js/store.esm.js", + "barcode_scanner/static/src/js/app.esm.js", + "barcode_scanner/static/src/js/services/feedback_service.esm.js", + "barcode_scanner/static/src/js/hooks/use_barcode.esm.js", + "barcode_scanner/static/src/js/hooks/use_barcode_handler.esm.js", + "barcode_scanner/static/src/js/hooks/use_barcode_dispatcher.esm.js", + "barcode_scanner/static/src/js/hooks/use_inventory.esm.js", + "barcode_scanner/static/src/js/screens/main_screen.esm.js", + ], + "web.assets_unit_tests": [ + "barcode_scanner/static/tests/**/*", + ], + }, + "installable": True, + "application": True, + "auto_install": False, +} diff --git a/barcode_scanner/i18n/es.po b/barcode_scanner/i18n/es.po new file mode 100644 index 0000000..b96e053 --- /dev/null +++ b/barcode_scanner/i18n/es.po @@ -0,0 +1,59 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * barcode_scanner +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 18.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2026-07-31 11:45+0000\n" +"PO-Revision-Date: 2026-07-31 11:45+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: es\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: barcode_scanner +#. odoo-javascript +#: code:addons/barcode_scanner/static/src/xml/barcode_scanner_templates.xml:0 +msgid "Avatar" +msgstr "Avatar" + +#. module: barcode_scanner +#. odoo-javascript +#: code:addons/barcode_scanner/static/src/js/hooks/use_barcode_dispatcher.js:0 +msgid "Barcode not recognized" +msgstr "Código de barras no reconocido" + +#. module: barcode_scanner +#. odoo-javascript +#: code:addons/barcode_scanner/static/src/js/screens/main_screen.js:0 +msgid "Good afternoon" +msgstr "Buenas tardes" + +#. module: barcode_scanner +#. odoo-javascript +#: code:addons/barcode_scanner/static/src/js/screens/main_screen.js:0 +msgid "Good evening" +msgstr "Buenas noches" + +#. module: barcode_scanner +#. odoo-javascript +#: code:addons/barcode_scanner/static/src/js/screens/main_screen.js:0 +msgid "Good morning" +msgstr "Buenos días" + +#. module: barcode_scanner +#. odoo-javascript +#: code:addons/barcode_scanner/static/src/xml/barcode_scanner_templates.xml:0 +msgid "Ready for today's distribution schedule." +msgstr "Listo para la planificación de distribución de hoy." + +#. module: barcode_scanner +#: model:ir.actions.client,name:barcode_scanner.action_barcode_scanner +#: model:ir.ui.menu,name:barcode_scanner.menu_barcode_scanner_root +msgid "Scanner" +msgstr "Escáner" diff --git a/barcode_scanner/pyproject.toml b/barcode_scanner/pyproject.toml new file mode 100644 index 0000000..4231d0c --- /dev/null +++ b/barcode_scanner/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/barcode_scanner/readme/CONTRIBUTORS.md b/barcode_scanner/readme/CONTRIBUTORS.md new file mode 100644 index 0000000..7a07748 --- /dev/null +++ b/barcode_scanner/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +* [Antonio David Ruban Espinal](https://github.com/antoniodavid) +* [Zuzanna Elzbieta Szalaty Szalaty](https://github.com/szalatyzuzanna) diff --git a/barcode_scanner/readme/DESCRIPTION.md b/barcode_scanner/readme/DESCRIPTION.md new file mode 100644 index 0000000..a7a63d6 --- /dev/null +++ b/barcode_scanner/readme/DESCRIPTION.md @@ -0,0 +1,14 @@ +This module is the **base framework** of the Barcode suite: a fast, +full-screen scanning application shell for Odoo that other modules extend. + +It ships no business logic of its own. Instead it exposes the building blocks +feature modules plug into, the same way Odoo widgets self-register: + +- a full-screen client action and a lightweight in-app router; +- registries for screens, scan handlers and home-screen menu tiles + (`barcode_screens`, `barcode_scan_handlers`, `barcode_menu_tiles`); +- the barcode input service (hardware/keyboard wedge), audio/vibration + feedback, an ORM/API wrapper and shared hooks. + +Install a feature module on top — such as `barcode_stock` — to get actual +warehouse operations. diff --git a/barcode_scanner/readme/USAGE.md b/barcode_scanner/readme/USAGE.md new file mode 100644 index 0000000..783a25d --- /dev/null +++ b/barcode_scanner/readme/USAGE.md @@ -0,0 +1,59 @@ +``barcode_scanner`` is a framework and is not useful on its own: install a +feature module such as ``barcode_stock`` to get actual operations. + +To build your own feature module, register your pieces into the framework +registries — no change to the base module is required. + +Register a screen: + +```js +import {barcodeScreens} from "@barcode_scanner/js/registries"; + +barcodeScreens.add("my_screen", {component: MyScreen}); +``` + +Register a scan handler (tried in ``sequence`` order; the first that returns a +truthy value consumes the scan): + +```js +import {barcodeScanHandlers} from "@barcode_scanner/js/registries"; + +barcodeScanHandlers.add("my_handler", { + async handle(barcode, parsed, {api, navigate, notify}) { + // return true when handled + }, +}, {sequence: 50}); +``` + +Register a home-screen tile: + +```js +import {barcodeMenuTiles} from "@barcode_scanner/js/registries"; + +barcodeMenuTiles.add("my_tile", { + label: "My Screen", + icon: "fa-cube", + action: ({navigate}) => navigate("my_screen"), +}, {sequence: 50}); +``` + +Register a barcode parser (tried in ``sequence`` order before the built-in +EAN13 one; return ``null`` to let the next parser try): + +```js +import {barcodeParsers} from "@barcode_scanner/js/registries"; + +barcodeParsers.add("my_symbology", (barcode) => { + // return {type: "...", value: "", ...} or null +}, {sequence: 20}); +``` + +Register a startup task, for data your module needs before the first scan +(``barcode_gs1`` reads its nomenclature this way). Tasks are awaited when the +app opens; one that fails is logged and skipped: + +```js +import {barcodeStartupTasks} from "@barcode_scanner/js/registries"; + +barcodeStartupTasks.add("my_config", (env) => loadMyConfig(env.services.orm)); +``` diff --git a/barcode_scanner/static/description/icon.png b/barcode_scanner/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..3a0328b516c4980e8e44cdb63fd945757ddd132d GIT binary patch literal 9455 zcmW++2RxMjAAjx~&dlBk9S+%}OXg)AGE&Cb*&}d0jUxM@u(PQx^-s)697TX`ehR4?GS^qbkof1cslKgkU)h65qZ9Oc=ml_0temigYLJfnz{IDzUf>bGs4N!v3=Z3jMq&A#7%rM5eQ#dc?k~! zVpnB`o+K7|Al`Q_U;eD$B zfJtP*jH`siUq~{KE)`jP2|#TUEFGRryE2`i0**z#*^6~AI|YzIWy$Cu#CSLW3q=GA z6`?GZymC;dCPk~rBS%eCb`5OLr;RUZ;D`}um=H)BfVIq%7VhiMr)_#G0N#zrNH|__ zc+blN2UAB0=617@>_u;MPHN;P;N#YoE=)R#i$k_`UAA>WWCcEVMh~L_ zj--gtp&|K1#58Yz*AHCTMziU1Jzt_jG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-%2y!7%)fAKjpEFsgQc4{amtiHb95KQEwvf<(3T<9-Zm$xIew#P22 zc2Ix|App^>v6(3L_MCU0d3W##AB0M~3D00EWoKZqsJYT(#@w$Y_H7G22M~ApVFTRHMI_3be)Lkn#0F*V8Pq zc}`Cjy$bE;FJ6H7p=0y#R>`}-m4(0F>%@P|?7fx{=R^uFdISRnZ2W_xQhD{YuR3t< z{6yxu=4~JkeA;|(J6_nv#>Nvs&FuLA&PW^he@t(UwFFE8)|a!R{`E`K`i^ZnyE4$k z;(749Ix|oi$c3QbEJ3b~D_kQsPz~fIUKym($a_7dJ?o+40*OLl^{=&oq$<#Q(yyrp z{J-FAniyAw9tPbe&IhQ|a`DqFTVQGQ&Gq3!C2==4x{6EJwiPZ8zub-iXoUtkJiG{} zPaR&}_fn8_z~(=;5lD-aPWD3z8PZS@AaUiomF!G8I}Mf>e~0g#BelA-5#`cj;O5>N Xviia!U7SGha1wx#SCgwmn*{w2TRX*I literal 0 HcmV?d00001 diff --git a/barcode_scanner/static/description/index.html b/barcode_scanner/static/description/index.html new file mode 100644 index 0000000..e97e35d --- /dev/null +++ b/barcode_scanner/static/description/index.html @@ -0,0 +1,500 @@ + + + + + +Barcode Scanner + + + +
+ + + +Odoo Community Association + +
+

Barcode Scanner

+ +

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

+

This module is the base framework of the Barcode suite: a fast, +full-screen scanning application shell for Odoo that other modules +extend.

+

It ships no business logic of its own. Instead it exposes the building +blocks feature modules plug into, the same way Odoo widgets +self-register:

+
    +
  • a full-screen client action and a lightweight in-app router;
  • +
  • registries for screens, scan handlers and home-screen menu tiles +(barcode_screens, barcode_scan_handlers, +barcode_menu_tiles);
  • +
  • the barcode input service (hardware/keyboard wedge), audio/vibration +feedback, an ORM/API wrapper and shared hooks.
  • +
+

Install a feature module on top — such as barcode_stock — to get +actual warehouse operations.

+

Table of contents

+ +
+

Usage

+

barcode_scanner is a framework and is not useful on its own: install +a feature module such as barcode_stock to get actual operations.

+

To build your own feature module, register your pieces into the +framework registries — no change to the base module is required.

+

Register a screen:

+
+import {barcodeScreens} from "@barcode_scanner/js/registries";
+
+barcodeScreens.add("my_screen", {component: MyScreen});
+
+

Register a scan handler (tried in sequence order; the first that +returns a truthy value consumes the scan):

+
+import {barcodeScanHandlers} from "@barcode_scanner/js/registries";
+
+barcodeScanHandlers.add("my_handler", {
+    async handle(barcode, parsed, {api, navigate, notify}) {
+        // return true when handled
+    },
+}, {sequence: 50});
+
+

Register a home-screen tile:

+
+import {barcodeMenuTiles} from "@barcode_scanner/js/registries";
+
+barcodeMenuTiles.add("my_tile", {
+    label: "My Screen",
+    icon: "fa-cube",
+    action: ({navigate}) => navigate("my_screen"),
+}, {sequence: 50});
+
+

Register a barcode parser (tried in sequence order before the +built-in EAN13 one; return null to let the next parser try):

+
+import {barcodeParsers} from "@barcode_scanner/js/registries";
+
+barcodeParsers.add("my_symbology", (barcode) => {
+    // return {type: "...", value: "<product code>", ...} or null
+}, {sequence: 20});
+
+

Register a startup task, for data your module needs before the first +scan (barcode_gs1 reads its nomenclature this way). Tasks are +awaited when the app opens; one that fails is logged and skipped:

+
+import {barcodeStartupTasks} from "@barcode_scanner/js/registries";
+
+barcodeStartupTasks.add("my_config", (env) => loadMyConfig(env.services.orm));
+
+
+
+

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

+
    +
  • Binhex
  • +
+
+ +
+

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:

+

szalatyzuzanna

+

This module is part of the OCA/barcode-interface project on GitHub.

+

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

+
+
+
+
+ + diff --git a/barcode_scanner/static/src/img/icon_barcode.svg b/barcode_scanner/static/src/img/icon_barcode.svg new file mode 100644 index 0000000..62b0945 --- /dev/null +++ b/barcode_scanner/static/src/img/icon_barcode.svg @@ -0,0 +1,65 @@ + + diff --git a/barcode_scanner/static/src/js/api.esm.js b/barcode_scanner/static/src/js/api.esm.js new file mode 100644 index 0000000..b4c18be --- /dev/null +++ b/barcode_scanner/static/src/js/api.esm.js @@ -0,0 +1,133 @@ +import {registry} from "@web/core/registry"; +import {_t} from "@web/core/l10n/translation"; + +// Server exceptions whose message is safe to show to operators. Anything +// else (real internal errors) falls back to a generic message so the PDA +// never displays raw Python tracebacks (which the RPC layer puts in +// error.data.debug, never read here). +// MissingError is included because the record is gone (operator can reload). +// AccessDenied is excluded because it signals authentication/session failure +// (generic message plus login flow, no raw detail). +const USER_ERROR_NAMES = new Set([ + "odoo.exceptions.UserError", + "odoo.exceptions.ValidationError", + "odoo.exceptions.AccessError", + "odoo.exceptions.MissingError", +]); + +export function errorMessage(error, fallback) { + const message = error?.data?.message; + return USER_ERROR_NAMES.has(error?.data?.name) && + typeof message === "string" && + message + ? message + : fallback; +} + +export const barcodeApiService = { + dependencies: ["orm", "notification", "dialog"], + start(env, {orm, notification, dialog}) { + return { + async call(model, method, args = [], kwargs = {}) { + try { + return await orm.call(model, method, args, kwargs); + } catch (error) { + const message = errorMessage( + error, + _t("An error occurred while calling the server.") + ); + notification.add(message, {type: "danger"}); + throw error; + } + }, + + async searchRead(model, domain, fields, options = {}) { + try { + return await orm.searchRead(model, domain, fields, options); + } catch (error) { + const message = errorMessage( + error, + _t("An error occurred while fetching data.") + ); + notification.add(message, {type: "danger"}); + throw error; + } + }, + + async readGroup(model, domain, fields, groupby, options = {}) { + try { + return await orm.readGroup(model, domain, fields, groupby, options); + } catch (error) { + const message = errorMessage( + error, + _t("An error occurred while grouping data.") + ); + notification.add(message, {type: "danger"}); + throw error; + } + }, + + async read(model, ids, fields) { + try { + return await orm.read(model, ids, fields); + } catch (error) { + const message = errorMessage( + error, + _t("An error occurred while reading records.") + ); + notification.add(message, {type: "danger"}); + throw error; + } + }, + + async write(model, ids, data) { + try { + return await orm.write(model, ids, data); + } catch (error) { + const message = errorMessage( + error, + _t("An error occurred while saving records.") + ); + notification.add(message, {type: "danger"}); + throw error; + } + }, + + async create(model, data) { + try { + return await orm.create(model, data); + } catch (error) { + const message = errorMessage( + error, + _t("An error occurred while creating records.") + ); + notification.add(message, {type: "danger"}); + throw error; + } + }, + + async unlink(model, ids) { + try { + return await orm.unlink(model, ids); + } catch (error) { + const message = errorMessage( + error, + _t("An error occurred while deleting records.") + ); + notification.add(message, {type: "danger"}); + throw error; + } + }, + + notify(message, options = {}) { + notification.add(message, options); + }, + + openDialog(dialogClass, props = {}) { + dialog.add(dialogClass, props); + }, + }; + }, +}; + +registry.category("services").add("barcodeApi", barcodeApiService); diff --git a/barcode_scanner/static/src/js/app.esm.js b/barcode_scanner/static/src/js/app.esm.js new file mode 100644 index 0000000..2a4467b --- /dev/null +++ b/barcode_scanner/static/src/js/app.esm.js @@ -0,0 +1,66 @@ +import {Component, onMounted, onWillStart, onWillUnmount, useState} from "@odoo/owl"; +import {registry} from "@web/core/registry"; +import {useService} from "@web/core/utils/hooks"; + +import "@barcode_scanner/js/services/feedback_service.esm"; + +import { + barcodeAppWidgets, + barcodeScreens, + barcodeStartupTasks, +} from "@barcode_scanner/js/registries.esm"; + +export class BarcodeScannerApp extends Component { + setup() { + this.barcode = useService("barcodeScannerBarcode"); + this.feedback = useState(useService("barcodeScannerFeedback")); + this.dialog = useService("dialog"); + this.router = useState(useService("barcodeRouter")); + if (!this.router.currentRoute) { + this.router.navigate("main"); + } + onWillStart(() => this.runStartupTasks()); + // Capture scans (incl. Android IME/soft-input PDAs) only while the app + // is open, so it never steals focus on the rest of the back office. + onMounted(() => this.barcode.activate()); + onWillUnmount(() => this.barcode.deactivate()); + } + + /** + * Let the installed feature modules warm up before the first scan. One + * failing task (a missing record, no access) must not keep the app closed, + * so each is caught on its own. + */ + async runStartupTasks() { + await Promise.all( + barcodeStartupTasks.getAll().map(async (task) => { + try { + await task(this.env); + } catch (error) { + console.warn("Barcode: a startup task failed", error); + } + }) + ); + } + + get currentScreen() { + const name = this.router.currentRoute?.name; + return name ? barcodeScreens.get(name, null) : null; + } + + get currentScreenProps() { + const entry = this.currentScreen; + const params = this.router.routeParams || {}; + const navigate = this.router.navigate.bind(this.router); + const extra = entry && entry.props ? entry.props(params) : {params}; + return {navigate, ...extra}; + } + + get appWidgets() { + return barcodeAppWidgets.getAll(); + } +} + +BarcodeScannerApp.template = "barcode_scanner.App"; + +registry.category("actions").add("barcode_scanner_app", BarcodeScannerApp); diff --git a/barcode_scanner/static/src/js/barcode.esm.js b/barcode_scanner/static/src/js/barcode.esm.js new file mode 100644 index 0000000..6059a81 --- /dev/null +++ b/barcode_scanner/static/src/js/barcode.esm.js @@ -0,0 +1,408 @@ +import {EventBus} from "@odoo/owl"; +import {registry} from "@web/core/registry"; +import {session} from "@web/session"; +import {parseBarcode} from "@barcode_scanner/js/barcode_parser.esm"; + +/** + * Barcode capture for the scanning SPA, built for the Munbyn Android PDAs used + * by Donaldson and Spartan. + * + * These PDAs deliver every laser scan through the Android input method (IME), + * not as real key events: each keystroke arrives as `keydown key="Unidentified"` + * (keyCode 0/229) and the actual code is committed as TEXT into the focused + * field's `.value`. So we keep a hidden, focused and read the scan from + * its `.value` on the terminating Enter/Tab (or shortly after the bulk `input` + * event for scanners that send no Enter). + * + * The input must STAY a plain editable field: anything that hides the Android + * soft keyboard for good -- `inputmode="none"` OR the VirtualKeyboard API -- + * also closes the IME composition session on this hardware, after which the + * scanner reads only once per Chrome session (proven on-device, see the + * barcode-pda-scanner-ime-only note). To keep the laser reading on every screen + * without the soft keyboard popping up, we focus() the field while it is + * briefly `readonly` and restore it to editable right after: a readonly field + * never raises the soft keyboard on Android Chrome, yet it stays focused and + * connected to the IME the whole time. Flip HIDE_SOFT_KEYBOARD below to false + * if a PDA stops reading after the first scan (its IME only injects while the + * keyboard is actually up). + * + * A permanent on-screen "scan feedback" toast shows the full code the PDA just + * read, then fades, so a misread or a dead scan is visible instead of silent. + */ + +// GS1 FNC1 group separator (the real control char the parser splits on). +const GS1_FNC1 = String.fromCharCode(29); + +// Scanners / the Android IME sometimes deliver the FNC1 separator not as the +// real 0x1D control char but as its visible Unicode symbol (U+241D), a nearby +// separator symbol, or a replacement box (U+FFFD). Normalise all back to 0x1D so +// the GS1 parser detects the barcode as GS1 and splits the AIs. +const GS1_SEPARATOR_VARIANTS = /[␝␞␟�]/g; +function normalizeGs1Separators(str) { + return str.replace(GS1_SEPARATOR_VARIANTS, GS1_FNC1); +} + +// For the on-screen feedback: render control chars (incl. the GS1 separator), +// the "control pictures" block and the replacement box as a visible middot, so +// the whole scanned code stays readable. +const NON_PRINTABLE = /[\x00-\x1f\x7f␀-␿�]/g; + +function isEditable(element) { + if (!element || element.nodeType !== 1) { + return false; + } + return ( + element.matches('input, textarea, select, [contenteditable="true"]') || + element.isContentEditable + ); +} + +// Real interactive targets the user is deliberately operating: we must not steal +// focus from these, so their own keyboard shows and they can type -- and native +// pop-ups (a