diff --git a/pos_product_multi_barcode/README.rst b/pos_product_multi_barcode/README.rst new file mode 100644 index 0000000000..9cf0bb3a37 --- /dev/null +++ b/pos_product_multi_barcode/README.rst @@ -0,0 +1,93 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +========================= +PoS Product multi barcode +========================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:9f76bd9121937cb6f997cf5b53fde50357291796f7e9d9daf7d2b05cd8a99add + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/19.0/pos_product_multi_barcode + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-19-0/pos-19-0-pos_product_multi_barcode + :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/pos&target_branch=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to use multiple barcode on a product from the PoS + +See +https://github.com/OCA/stock-logistics-barcode/tree/14.0/product_multi_barcode + +**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 +------- + +* Akretion + +Contributors +------------ + + - Pierrick Brun + - Ilyas + - Nguyen Minh Chien + - Ariel Barreiros + `arielbarreiros96 `__: + +Other credits +------------- + +The migration of this module from 14.0 to 16.0 was financially supported +by Camptocamp + +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/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_product_multi_barcode/__init__.py b/pos_product_multi_barcode/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_product_multi_barcode/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_product_multi_barcode/__manifest__.py b/pos_product_multi_barcode/__manifest__.py new file mode 100644 index 0000000000..47b86a9a0c --- /dev/null +++ b/pos_product_multi_barcode/__manifest__.py @@ -0,0 +1,21 @@ +{ + "name": "PoS Product multi barcode", + "summary": "Make product multi barcodes usable in the point of sale", + "version": "19.0.1.0.0", + "category": "Point of Sale", + "website": "https://github.com/OCA/pos", + "author": "Akretion, Odoo Community Association (OCA)", + "maintainer": "PierrickBrun", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "point_of_sale", + "product_multi_barcode", + ], + "assets": { + "point_of_sale._assets_pos": [ + "pos_product_multi_barcode/static/src/app/store/product_product.esm.js", + ] + }, +} diff --git a/pos_product_multi_barcode/i18n/es.po b/pos_product_multi_barcode/i18n/es.po new file mode 100644 index 0000000000..7d15cd7622 --- /dev/null +++ b/pos_product_multi_barcode/i18n/es.po @@ -0,0 +1,32 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_product_multi_barcode +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-02-08 22:35+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: none\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" +"X-Generator: Weblate 4.17\n" + +#. module: pos_product_multi_barcode +#: model:ir.model,name:pos_product_multi_barcode.model_pos_session +msgid "Point of Sale Session" +msgstr "Sesión del Punto de Venta" + +#. module: pos_product_multi_barcode +#: model:ir.model,name:pos_product_multi_barcode.model_product_product +msgid "Product Variant" +msgstr "Variante del Producto" + +#. module: pos_product_multi_barcode +#: model:ir.model.fields,field_description:pos_product_multi_barcode.field_product_product__barcodes_json +msgid "barcode list" +msgstr "lista de código de barras" diff --git a/pos_product_multi_barcode/i18n/it.po b/pos_product_multi_barcode/i18n/it.po new file mode 100644 index 0000000000..edeef49540 --- /dev/null +++ b/pos_product_multi_barcode/i18n/it.po @@ -0,0 +1,44 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_product_multi_barcode +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2023-11-23 19:35+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 4.17\n" + +#. module: pos_product_multi_barcode +#: model:ir.model,name:pos_product_multi_barcode.model_pos_session +msgid "Point of Sale Session" +msgstr "Sessione punto vendita" + +#. module: pos_product_multi_barcode +#: model:ir.model,name:pos_product_multi_barcode.model_product_product +msgid "Product Variant" +msgstr "Variante prodotto" + +#. module: pos_product_multi_barcode +#: model:ir.model.fields,field_description:pos_product_multi_barcode.field_product_product__barcodes_json +msgid "barcode list" +msgstr "elenco codici a barre" + +#~ msgid "Display Name" +#~ msgstr "Nome visualizzato" + +#~ msgid "ID" +#~ msgstr "ID" + +#~ msgid "Last Modified on" +#~ msgstr "Ultima modifica il" + +#~ msgid "Product" +#~ msgstr "Prodotto" diff --git a/pos_product_multi_barcode/i18n/pos_product_multi_barcode.pot b/pos_product_multi_barcode/i18n/pos_product_multi_barcode.pot new file mode 100644 index 0000000000..57795bfbe6 --- /dev/null +++ b/pos_product_multi_barcode/i18n/pos_product_multi_barcode.pot @@ -0,0 +1,24 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_product_multi_barcode +# +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: pos_product_multi_barcode +#: model:ir.model,name:pos_product_multi_barcode.model_product_product +msgid "Product Variant" +msgstr "" + +#. module: pos_product_multi_barcode +#: model:ir.model.fields,field_description:pos_product_multi_barcode.field_product_product__barcodes_json +msgid "barcode list" +msgstr "" diff --git a/pos_product_multi_barcode/models/__init__.py b/pos_product_multi_barcode/models/__init__.py new file mode 100644 index 0000000000..9649db77a1 --- /dev/null +++ b/pos_product_multi_barcode/models/__init__.py @@ -0,0 +1 @@ +from . import product diff --git a/pos_product_multi_barcode/models/product.py b/pos_product_multi_barcode/models/product.py new file mode 100644 index 0000000000..57503556d8 --- /dev/null +++ b/pos_product_multi_barcode/models/product.py @@ -0,0 +1,27 @@ +# Copyright 2022 Akretion (https://www.akretion.com). +# @author Pierrick Brun +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import json + +from odoo import api, fields, models + + +class ProductProduct(models.Model): + _inherit = "product.product" + + # technical field used in POS frontend + barcodes_json = fields.Char( + "barcode list", readonly=True, compute="_compute_barcodes_json" + ) + + @api.depends("barcode_ids.name") + def _compute_barcodes_json(self): + for product in self: + barcodes = list(product.mapped("barcode_ids.name")) + product.barcodes_json = json.dumps(barcodes) + + @api.model + def _load_pos_data_fields(self, config): + fields = super()._load_pos_data_fields(config) + return list(dict.fromkeys(fields + ["barcodes_json"])) diff --git a/pos_product_multi_barcode/pyproject.toml b/pos_product_multi_barcode/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/pos_product_multi_barcode/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/pos_product_multi_barcode/readme/CONTRIBUTORS.md b/pos_product_multi_barcode/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..f0f42f1210 --- /dev/null +++ b/pos_product_multi_barcode/readme/CONTRIBUTORS.md @@ -0,0 +1,4 @@ +> - Pierrick Brun \ +> - Ilyas \ +> - Nguyen Minh Chien \ +> - Ariel Barreiros [arielbarreiros96](https://github.com/arielbarreiros96): \ No newline at end of file diff --git a/pos_product_multi_barcode/readme/CREDITS.md b/pos_product_multi_barcode/readme/CREDITS.md new file mode 100644 index 0000000000..44a6233517 --- /dev/null +++ b/pos_product_multi_barcode/readme/CREDITS.md @@ -0,0 +1,2 @@ +The migration of this module from 14.0 to 16.0 was financially supported +by Camptocamp diff --git a/pos_product_multi_barcode/readme/DESCRIPTION.md b/pos_product_multi_barcode/readme/DESCRIPTION.md new file mode 100644 index 0000000000..c004e16839 --- /dev/null +++ b/pos_product_multi_barcode/readme/DESCRIPTION.md @@ -0,0 +1,4 @@ +This module allows to use multiple barcode on a product from the PoS + +See + diff --git a/pos_product_multi_barcode/static/description/icon.png b/pos_product_multi_barcode/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/pos_product_multi_barcode/static/description/icon.png differ diff --git a/pos_product_multi_barcode/static/description/index.html b/pos_product_multi_barcode/static/description/index.html new file mode 100644 index 0000000000..47f9f140e7 --- /dev/null +++ b/pos_product_multi_barcode/static/description/index.html @@ -0,0 +1,443 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

PoS Product multi barcode

+ +

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

+

This module allows to use multiple barcode on a product from the PoS

+

See +https://github.com/OCA/stock-logistics-barcode/tree/14.0/product_multi_barcode

+

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

+
    +
  • Akretion
  • +
+
+
+

Contributors

+
+ +
+
+
+

Other credits

+

The migration of this module from 14.0 to 16.0 was financially supported +by Camptocamp

+
+
+

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/pos project on GitHub.

+

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

+
+
+
+
+ + diff --git a/pos_product_multi_barcode/static/src/app/store/product_product.esm.js b/pos_product_multi_barcode/static/src/app/store/product_product.esm.js new file mode 100644 index 0000000000..89bd872235 --- /dev/null +++ b/pos_product_multi_barcode/static/src/app/store/product_product.esm.js @@ -0,0 +1,49 @@ +import {ProductProduct} from "@point_of_sale/app/models/product_product"; +import {STORE_SYMBOL} from "@point_of_sale/app/models/related_models/utils"; +import {patch} from "@web/core/utils/patch"; + +patch(ProductProduct.prototype, { + setup(vals) { + super.setup(vals); + this._indexExtraBarcodes(); + }, + + get searchString() { + let str = super.searchString; + for (const barcode of this._getExtraBarcodes()) { + str += " " + barcode; + } + return str; + }, + + _getExtraBarcodes() { + if (!this.barcodes_json) { + return []; + } + try { + return JSON.parse(this.barcodes_json).filter(Boolean); + } catch { + return []; + } + }, + + // Register every barcode of the product in the "barcode" index so that + // scanning a non-primary barcode resolves the product, instead of only the + // main `barcode` field (default POS behaviour). + _indexExtraBarcodes() { + const barcodes = this._getExtraBarcodes(); + if (!barcodes.length) { + return; + } + const store = this[STORE_SYMBOL]; + if (!store?.hasIndex("product.product", "barcode")) { + return; + } + const barcodeMap = store.getRecordsMap("product.product", "barcode"); + for (const barcode of barcodes) { + if (!barcodeMap.has(barcode)) { + barcodeMap.set(barcode, this); + } + } + }, +}); diff --git a/pos_product_multi_barcode/tests/__init__.py b/pos_product_multi_barcode/tests/__init__.py new file mode 100644 index 0000000000..0f7da46cc4 --- /dev/null +++ b/pos_product_multi_barcode/tests/__init__.py @@ -0,0 +1,2 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from . import test_pos_product_multi_barcode diff --git a/pos_product_multi_barcode/tests/test_pos_product_multi_barcode.py b/pos_product_multi_barcode/tests/test_pos_product_multi_barcode.py new file mode 100644 index 0000000000..5490b8b533 --- /dev/null +++ b/pos_product_multi_barcode/tests/test_pos_product_multi_barcode.py @@ -0,0 +1,54 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +import json + +from odoo.tests import TransactionCase, tagged + + +@tagged("post_install", "-at_install") +class TestPosProductMultiBarcode(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.product = cls.env["product.product"].create({"name": "Test product"}) + cls.barcode_a = "MULTI-BARCODE-A" + cls.barcode_b = "MULTI-BARCODE-B" + cls.config = cls.env["pos.config"].create({"name": "Test POS"}) + + def test_barcodes_json_empty_when_no_barcodes(self): + self.assertEqual(json.loads(self.product.barcodes_json), []) + + def test_barcodes_json_lists_all_barcodes_in_sequence(self): + self.product.barcode_ids = [ + (0, 0, {"name": self.barcode_b, "sequence": 20}), + (0, 0, {"name": self.barcode_a, "sequence": 10}), + ] + self.assertEqual( + json.loads(self.product.barcodes_json), + [self.barcode_a, self.barcode_b], + ) + + def test_barcodes_json_is_valid_json_string(self): + self.product.barcode_ids = [(0, 0, {"name": self.barcode_a})] + self.assertIsInstance(self.product.barcodes_json, str) + self.assertEqual(json.loads(self.product.barcodes_json), [self.barcode_a]) + + def test_barcodes_json_recomputes_when_barcodes_change(self): + self.product.barcode_ids = [ + (0, 0, {"name": self.barcode_a}), + (0, 0, {"name": self.barcode_b}), + ] + self.assertEqual(len(json.loads(self.product.barcodes_json)), 2) + self.product.barcode_ids.filtered(lambda b: b.name == self.barcode_a).unlink() + self.assertEqual(json.loads(self.product.barcodes_json), [self.barcode_b]) + + def test_load_pos_data_fields_includes_barcodes_json(self): + fields = self.product._load_pos_data_fields(self.config) + self.assertIn("barcodes_json", fields) + + def test_load_pos_data_fields_does_not_duplicate_barcodes_json(self): + fields = self.product._load_pos_data_fields(self.config) + self.assertEqual(fields.count("barcodes_json"), 1) + + def test_load_pos_data_fields_keeps_core_barcode_field(self): + fields = self.product._load_pos_data_fields(self.config) + self.assertIn("barcode", fields) diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..6dfcbe83d5 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-product_multi_barcode @ git+https://github.com/OCA/stock-logistics-barcode.git@refs/pull/723/head#subdirectory=product_multi_barcode