From b56936fe85e9fc060edc3326745dc20e456512d6 Mon Sep 17 00:00:00 2001 From: eLBati Date: Mon, 2 Mar 2020 08:04:21 +0100 Subject: [PATCH 1/2] ADD pos_supplierinfo_barcode: Search products by supplier barcode --- oca_dependencies.txt | 1 + pos_supplierinfo_barcode/__init__.py | 1 + pos_supplierinfo_barcode/__manifest__.py | 26 +++++++++++++++++ pos_supplierinfo_barcode/models/__init__.py | 1 + pos_supplierinfo_barcode/models/product.py | 17 +++++++++++ pos_supplierinfo_barcode/readme/CONFIGURE.rst | 1 + .../readme/CONTRIBUTORS.rst | 1 + .../readme/DESCRIPTION.rst | 1 + pos_supplierinfo_barcode/readme/USAGE.rst | 1 + pos_supplierinfo_barcode/static/src/js/db.js | 29 +++++++++++++++++++ pos_supplierinfo_barcode/views/assets.xml | 10 +++++++ 11 files changed, 89 insertions(+) create mode 100644 pos_supplierinfo_barcode/__init__.py create mode 100644 pos_supplierinfo_barcode/__manifest__.py create mode 100644 pos_supplierinfo_barcode/models/__init__.py create mode 100644 pos_supplierinfo_barcode/models/product.py create mode 100644 pos_supplierinfo_barcode/readme/CONFIGURE.rst create mode 100644 pos_supplierinfo_barcode/readme/CONTRIBUTORS.rst create mode 100644 pos_supplierinfo_barcode/readme/DESCRIPTION.rst create mode 100644 pos_supplierinfo_barcode/readme/USAGE.rst create mode 100644 pos_supplierinfo_barcode/static/src/js/db.js create mode 100644 pos_supplierinfo_barcode/views/assets.xml diff --git a/oca_dependencies.txt b/oca_dependencies.txt index e0b1a2ca..0bbc6e4c 100644 --- a/oca_dependencies.txt +++ b/oca_dependencies.txt @@ -1,2 +1,3 @@ queue partner-contact +stock-logistics-barcode diff --git a/pos_supplierinfo_barcode/__init__.py b/pos_supplierinfo_barcode/__init__.py new file mode 100644 index 00000000..0650744f --- /dev/null +++ b/pos_supplierinfo_barcode/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_supplierinfo_barcode/__manifest__.py b/pos_supplierinfo_barcode/__manifest__.py new file mode 100644 index 00000000..91ab42d0 --- /dev/null +++ b/pos_supplierinfo_barcode/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2020 Lorenzo Battistini @ TAKOBI +# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl). +{ + "name": "Point of sale - Supplier barcodes", + "summary": "Search products by supplier barcode", + "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": "LGPL-3", + "application": False, + "installable": True, + "auto_install": True, + "preloadable": True, + "depends": [ + "product_supplierinfo_barcode", + "point_of_sale", + ], + "data": [ + "views/assets.xml", + ], + "demo": [ + ], +} diff --git a/pos_supplierinfo_barcode/models/__init__.py b/pos_supplierinfo_barcode/models/__init__.py new file mode 100644 index 00000000..9649db77 --- /dev/null +++ b/pos_supplierinfo_barcode/models/__init__.py @@ -0,0 +1 @@ +from . import product diff --git a/pos_supplierinfo_barcode/models/product.py b/pos_supplierinfo_barcode/models/product.py new file mode 100644 index 00000000..d6cca3d3 --- /dev/null +++ b/pos_supplierinfo_barcode/models/product.py @@ -0,0 +1,17 @@ +import json +from odoo import models, fields, api + + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + # technical field used in POS frontend + supplier_barcode_json = fields.Char( + "Supplier barcode list", readonly=True, + compute="_compute_supplier_barcode_json") + + @api.multi + def _compute_supplier_barcode_json(self): + for t in self: + supplier_barcode_json = [x for x in t.mapped('seller_ids.barcode') if x] + t.supplier_barcode_json = json.dumps(supplier_barcode_json) diff --git a/pos_supplierinfo_barcode/readme/CONFIGURE.rst b/pos_supplierinfo_barcode/readme/CONFIGURE.rst new file mode 100644 index 00000000..c9746551 --- /dev/null +++ b/pos_supplierinfo_barcode/readme/CONFIGURE.rst @@ -0,0 +1 @@ +Open product form and click purchase tab. In Vendors lines, set Barcode field. diff --git a/pos_supplierinfo_barcode/readme/CONTRIBUTORS.rst b/pos_supplierinfo_barcode/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..b27b50b5 --- /dev/null +++ b/pos_supplierinfo_barcode/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Lorenzo Battistini (https://takobi.online) diff --git a/pos_supplierinfo_barcode/readme/DESCRIPTION.rst b/pos_supplierinfo_barcode/readme/DESCRIPTION.rst new file mode 100644 index 00000000..c341120d --- /dev/null +++ b/pos_supplierinfo_barcode/readme/DESCRIPTION.rst @@ -0,0 +1 @@ +In point of sale interface, allow to scan suppliers barcodes to add products to order. diff --git a/pos_supplierinfo_barcode/readme/USAGE.rst b/pos_supplierinfo_barcode/readme/USAGE.rst new file mode 100644 index 00000000..877c79d8 --- /dev/null +++ b/pos_supplierinfo_barcode/readme/USAGE.rst @@ -0,0 +1 @@ +In point of sale interface, just scan a barcode configured for a supplier. The product will be added to order. diff --git a/pos_supplierinfo_barcode/static/src/js/db.js b/pos_supplierinfo_barcode/static/src/js/db.js new file mode 100644 index 00000000..af2fb05c --- /dev/null +++ b/pos_supplierinfo_barcode/static/src/js/db.js @@ -0,0 +1,29 @@ +odoo.define('pos_supplierinfo_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", ["supplier_barcode_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 supplier_barcode_list = JSON.parse(product.supplier_barcode_json); + + for(var j = 0, jlen = supplier_barcode_list.length; j < jlen; j++){ + var supplier_barcode = supplier_barcode_list[j]; + this.product_by_barcode[supplier_barcode] = product; + } + } + return res; + }, + }); + +}); diff --git a/pos_supplierinfo_barcode/views/assets.xml b/pos_supplierinfo_barcode/views/assets.xml new file mode 100644 index 00000000..6aa43686 --- /dev/null +++ b/pos_supplierinfo_barcode/views/assets.xml @@ -0,0 +1,10 @@ + + + +