From 42e097cdf6e59564564f966f33f43a1582b763bb Mon Sep 17 00:00:00 2001 From: Pierrick Brun Date: Tue, 22 Mar 2022 12:34:30 +0100 Subject: [PATCH 01/24] [ADD] pos_product_multi_barcode --- pos_product_multi_barcode/__init__.py | 1 + pos_product_multi_barcode/__manifest__.py | 20 ++++++++++++++ pos_product_multi_barcode/models/__init__.py | 1 + pos_product_multi_barcode/models/product.py | 21 +++++++++++++++ .../readme/DESCRIPTION.rst | 3 +++ pos_product_multi_barcode/static/src/js/db.js | 27 +++++++++++++++++++ .../templates/assets.xml | 13 +++++++++ 7 files changed, 86 insertions(+) create mode 100644 pos_product_multi_barcode/__init__.py create mode 100644 pos_product_multi_barcode/__manifest__.py create mode 100644 pos_product_multi_barcode/models/__init__.py create mode 100644 pos_product_multi_barcode/models/product.py create mode 100644 pos_product_multi_barcode/readme/DESCRIPTION.rst create mode 100644 pos_product_multi_barcode/static/src/js/db.js create mode 100644 pos_product_multi_barcode/templates/assets.xml 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..0be19b5385 --- /dev/null +++ b/pos_product_multi_barcode/__manifest__.py @@ -0,0 +1,20 @@ +{ + "name": "PoS Product multi barcode", + "summary": "Make product multi barcodes usable in the point of sale", + "version": "14.0.1.0.0", + "category": "Point of Sale", + "website": "https://github.com/OCA/pos", + "author": "Akretion, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": [ + "point_of_sale", + "product_multi_barcode", + ], + "data": [ + "templates/assets.xml", + ], + "demo": [], + "qweb": [], +} 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..09aa3b39f5 --- /dev/null +++ b/pos_product_multi_barcode/models/product.py @@ -0,0 +1,21 @@ +# 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 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" + ) + + def _compute_barcodes_json(self): + for product in self: + barcodes = [barcode for barcode in product.mapped("barcode_ids.name")] + product.barcodes_json = json.dumps(barcodes) diff --git a/pos_product_multi_barcode/readme/DESCRIPTION.rst b/pos_product_multi_barcode/readme/DESCRIPTION.rst new file mode 100644 index 0000000000..500714250e --- /dev/null +++ b/pos_product_multi_barcode/readme/DESCRIPTION.rst @@ -0,0 +1,3 @@ +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 diff --git a/pos_product_multi_barcode/static/src/js/db.js b/pos_product_multi_barcode/static/src/js/db.js new file mode 100644 index 0000000000..75a04f978f --- /dev/null +++ b/pos_product_multi_barcode/static/src/js/db.js @@ -0,0 +1,27 @@ +odoo.define("pos_product_multi_barcode.db", function (require) { + "use strict"; + + var PosDB = require("point_of_sale.DB"); + var models = require("point_of_sale.models"); + + models.load_fields("product.product", ["barcodes_json"]); + + PosDB.include({ + add_products: function (products) { + var res = this._super(products); + var self = this; + + if (!products instanceof Array) { + products = [products]; + } + products.forEach(function (product) { + var barcodes = JSON.parse(product.barcodes_json); + + barcodes.forEach(function (barcode) { + self.product_by_barcode[barcode] = product; + }); + }); + return res; + }, + }); +}); diff --git a/pos_product_multi_barcode/templates/assets.xml b/pos_product_multi_barcode/templates/assets.xml new file mode 100644 index 0000000000..6b6a1c6314 --- /dev/null +++ b/pos_product_multi_barcode/templates/assets.xml @@ -0,0 +1,13 @@ + + + +