From 4ab5fa28e89b4c5d96cdb03ee7854ffd1ee4f03a Mon Sep 17 00:00:00 2001 From: luis Date: Mon, 14 Apr 2025 11:20:29 +0200 Subject: [PATCH] Avecinal/avecinal#70 add pos_product_hide_subcategory module. Only show products of the selected category in the PoS --- pos_product_hide_subcategory/README.rst | 5 +++ pos_product_hide_subcategory/__init__.py | 0 pos_product_hide_subcategory/__manifest__.py | 19 ++++++++++ .../static/src/js/db.js | 38 +++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 pos_product_hide_subcategory/README.rst create mode 100644 pos_product_hide_subcategory/__init__.py create mode 100644 pos_product_hide_subcategory/__manifest__.py create mode 100644 pos_product_hide_subcategory/static/src/js/db.js diff --git a/pos_product_hide_subcategory/README.rst b/pos_product_hide_subcategory/README.rst new file mode 100644 index 0000000..0a2d9cd --- /dev/null +++ b/pos_product_hide_subcategory/README.rst @@ -0,0 +1,5 @@ +============================ +Pos Product Hide Subcategory +============================ + +Displays only the products of the selected category, hiding those of the child categories. diff --git a/pos_product_hide_subcategory/__init__.py b/pos_product_hide_subcategory/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pos_product_hide_subcategory/__manifest__.py b/pos_product_hide_subcategory/__manifest__.py new file mode 100644 index 0000000..35288ce --- /dev/null +++ b/pos_product_hide_subcategory/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2025 Criptomart +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Pos Product Hide Subcategory", + "summary": """Displays only the products of the selected category, hiding those of the child categories.""", + "version": "16.0.1.0.0", + "license": "AGPL-3", + "author": "Criptomart", + "website": "https://criptomart.net", + "depends": ["point_of_sale"], + "assets": { + "point_of_sale.assets": [ + "pos_product_hide_subcategory/static/src/js/db.js", + ] + }, + "data": [], + "demo": [], +} diff --git a/pos_product_hide_subcategory/static/src/js/db.js b/pos_product_hide_subcategory/static/src/js/db.js new file mode 100644 index 0000000..04f1aaf --- /dev/null +++ b/pos_product_hide_subcategory/static/src/js/db.js @@ -0,0 +1,38 @@ +odoo.define("pos_product_hide_subcategory.db", function (require) { + "use strict"; + + var PosDB = require("point_of_sale.DB"); + var utils = require('web.utils'); + + PosDB.include({ + add_products: function (products) { + var stored_categories = this.product_by_category_id; + + if(!(products instanceof Array)){ + products = [products]; + } + for(var i = 0, len = products.length; i < len; i++){ + var product = products[i]; + if (product.id in this.product_by_id) continue; + if (product.available_in_pos){ + var search_string = utils.unaccent(this._product_search_string(product)); + var categ_id = product.pos_categ_id ? product.pos_categ_id[0] : this.root_category_id; + product.product_tmpl_id = product.product_tmpl_id[0]; + if(!stored_categories[categ_id]){ + stored_categories[categ_id] = []; + } + stored_categories[categ_id].push(product.id); + + if(this.category_search_string[categ_id] === undefined){ + this.category_search_string[categ_id] = ''; + } + this.category_search_string[categ_id] += search_string; + } + this.product_by_id[product.id] = product; + if(product.barcode && product.active){ + this.product_by_barcode[product.barcode] = product; + } + } + }, + }); +}); \ No newline at end of file