diff --git a/pos_multi_ean/__init__.py b/pos_multi_ean/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/pos_multi_ean/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_multi_ean/__manifest__.py b/pos_multi_ean/__manifest__.py new file mode 100644 index 00000000..4de06e9c --- /dev/null +++ b/pos_multi_ean/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2020 Lorenzo Battistini @ TAKOBI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +{ + "name": "Point of sale - Multi EAN support", + "summary": "Search products by multiple EAN", + "version": "12.0.1.0.0", + "development_status": "Beta", + "category": "Point Of Sale", + "website": "https://github.com/OCA/pos", + "author": "TAKOBI, Odoo Community Association (OCA)", + "maintainers": ["eLBati"], + "license": "AGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "depends": [ + "product_multi_ean", + "point_of_sale", + ], + "data": [ + "views/assets.xml", + ], + "demo": [ + ], +} diff --git a/pos_multi_ean/models/__init__.py b/pos_multi_ean/models/__init__.py new file mode 100644 index 00000000..9649db77 --- /dev/null +++ b/pos_multi_ean/models/__init__.py @@ -0,0 +1 @@ +from . import product diff --git a/pos_multi_ean/models/product.py b/pos_multi_ean/models/product.py new file mode 100644 index 00000000..8e91ae40 --- /dev/null +++ b/pos_multi_ean/models/product.py @@ -0,0 +1,17 @@ +import json +from odoo import models, fields, api + + +class Product(models.Model): + _inherit = 'product.product' + + # technical field used in POS frontend + multi_ean_json = fields.Char( + "Multi EAN list", readonly=True, + compute="_compute_multi_ean_json") + + @api.multi + def _compute_multi_ean_json(self): + for p in self: + multi_ean_json = [x for x in p.mapped('ean13_ids.name') if x] + p.multi_ean_json = json.dumps(multi_ean_json) diff --git a/pos_multi_ean/readme/CONFIGURE.rst b/pos_multi_ean/readme/CONFIGURE.rst new file mode 100644 index 00000000..ea98ecae --- /dev/null +++ b/pos_multi_ean/readme/CONFIGURE.rst @@ -0,0 +1 @@ +Open product (variant) form and add EAN13 lines. diff --git a/pos_multi_ean/readme/CONTRIBUTORS.rst b/pos_multi_ean/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b27b50b5 --- /dev/null +++ b/pos_multi_ean/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Lorenzo Battistini (https://takobi.online) diff --git a/pos_multi_ean/readme/DESCRIPTION.rst b/pos_multi_ean/readme/DESCRIPTION.rst new file mode 100644 index 00000000..84c91cd5 --- /dev/null +++ b/pos_multi_ean/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +In point of sale interface, allow to search products by multiple EAN (defined by product_multi_ean module) while scanning product barcode to add it to order. diff --git a/pos_multi_ean/readme/USAGE.rst b/pos_multi_ean/readme/USAGE.rst new file mode 100644 index 00000000..7b09f4e3 --- /dev/null +++ b/pos_multi_ean/readme/USAGE.rst @@ -0,0 +1 @@ +In point of sale interface, just scan a barcode previously added to EAN13 list. The product will be added to order. diff --git a/pos_multi_ean/static/src/js/db.js b/pos_multi_ean/static/src/js/db.js new file mode 100644 index 00000000..0ca3aa58 --- /dev/null +++ b/pos_multi_ean/static/src/js/db.js @@ -0,0 +1,29 @@ +odoo.define('pos_multi_ean.db', function (require) { + "use strict"; + + var PosDB = require('point_of_sale.DB'); + var models = require('point_of_sale.models'); + + models.load_fields("product.product", ["multi_ean_json"]); + + PosDB.include({ + add_products: function(products) { + var res = this._super(products); + + if(!products instanceof Array){ + products = [products]; + } + for(var i = 0, len = products.length; i < len; i++){ + var product = products[i]; + var multi_ean_list = JSON.parse(product.multi_ean_json); + + for(var j = 0, jlen = multi_ean_list.length; j < jlen; j++){ + var ean = multi_ean_list[j]; + this.product_by_barcode[ean] = product; + } + } + return res; + }, + }); + +}); diff --git a/pos_multi_ean/views/assets.xml b/pos_multi_ean/views/assets.xml new file mode 100644 index 00000000..3927abb5 --- /dev/null +++ b/pos_multi_ean/views/assets.xml @@ -0,0 +1,10 @@ + + + +