From 4138961cb22e335890e87aeb32ef715588eade1b Mon Sep 17 00:00:00 2001 From: Carmen Bianca Bakker Date: Thu, 5 May 2022 10:38:49 +0200 Subject: [PATCH 01/16] [ADD] rotordc_one_optional_product_per_categ Signed-off-by: Carmen Bianca Bakker --- .../__init__.py | 0 .../__manifest__.py | 25 +++++++++++++++ .../readme/CONTRIBUTORS.rst | 3 ++ .../readme/DESCRIPTION.rst | 0 .../src/js/product_configurator_modal.js | 32 +++++++++++++++++++ .../views/assets.xml | 15 +++++++++ .../sale_product_configurator_templates.xml | 12 +++++++ .../rotordc_one_optional_product_per_categ | 1 + .../setup.py | 6 ++++ 9 files changed, 94 insertions(+) create mode 100644 rotordc_one_optional_product_per_categ/__init__.py create mode 100644 rotordc_one_optional_product_per_categ/__manifest__.py create mode 100644 rotordc_one_optional_product_per_categ/readme/CONTRIBUTORS.rst create mode 100644 rotordc_one_optional_product_per_categ/readme/DESCRIPTION.rst create mode 100644 rotordc_one_optional_product_per_categ/static/src/js/product_configurator_modal.js create mode 100644 rotordc_one_optional_product_per_categ/views/assets.xml create mode 100644 rotordc_one_optional_product_per_categ/views/sale_product_configurator_templates.xml create mode 120000 setup/rotordc_one_optional_product_per_categ/odoo/addons/rotordc_one_optional_product_per_categ create mode 100644 setup/rotordc_one_optional_product_per_categ/setup.py diff --git a/rotordc_one_optional_product_per_categ/__init__.py b/rotordc_one_optional_product_per_categ/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/rotordc_one_optional_product_per_categ/__manifest__.py b/rotordc_one_optional_product_per_categ/__manifest__.py new file mode 100644 index 00000000..9dafe780 --- /dev/null +++ b/rotordc_one_optional_product_per_categ/__manifest__.py @@ -0,0 +1,25 @@ +# Copyright 2022 Coop IT Easy SCRLfs +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +{ + "name": "RotorDC One Optional Product Per Category", + "summary": """ + Only allow one optional product in the eCommerce per internal category.""", + "version": "12.0.1.0.0", + "category": "Sales", + "website": "https://coopiteasy.be", + "author": "Coop IT Easy SCRLfs", + "license": "AGPL-3", + "application": False, + "depends": [ + "sale", + "web", + ], + "excludes": [], + "data": [ + "views/assets.xml", + "views/sale_product_configurator_templates.xml", + ], + "demo": [], + "qweb": [], +} diff --git a/rotordc_one_optional_product_per_categ/readme/CONTRIBUTORS.rst b/rotordc_one_optional_product_per_categ/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..9f39efbc --- /dev/null +++ b/rotordc_one_optional_product_per_categ/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Coop IT Easy SCRLfs `_: + + * Carmen Bianca Bakker diff --git a/rotordc_one_optional_product_per_categ/readme/DESCRIPTION.rst b/rotordc_one_optional_product_per_categ/readme/DESCRIPTION.rst new file mode 100644 index 00000000..e69de29b diff --git a/rotordc_one_optional_product_per_categ/static/src/js/product_configurator_modal.js b/rotordc_one_optional_product_per_categ/static/src/js/product_configurator_modal.js new file mode 100644 index 00000000..4a84f01a --- /dev/null +++ b/rotordc_one_optional_product_per_categ/static/src/js/product_configurator_modal.js @@ -0,0 +1,32 @@ +odoo.define("rotordc_one_optional_product_per_categ.o_p_modal", function (require) { + "use strict"; + + var OptionalProductsModal = require("sale.OptionalProductsModal"); + + OptionalProductsModal.include({ + _getCategId: function (element) { + return element.find("input.product_categ_id").val(); + }, + _categIdFromProductId: function (product_id) { + var product = this.$modal.find(`input.product_id[value=${product_id}]`); + if (product === null) { + // FIXME: error handling idk + return undefined; + } + product = product.parents(".js_product:first"); + return this._getCategId(product); + }, + _onAddOption: function ($modal, $parent, productTemplateId) { + var categ_id = this._getCategId($parent); + var products = this.getSelectedProducts(); + for (var i = 0; i < products.length; i++) { + if (this._categIdFromProductId(products[i].product_id) === categ_id) { + // TODO: Pop-up, cleanly abort. + console.log("SAME CATEGORY ABORT"); + return; + } + } + this._super($modal, $parent, productTemplateId); + }, + }); +}); diff --git a/rotordc_one_optional_product_per_categ/views/assets.xml b/rotordc_one_optional_product_per_categ/views/assets.xml new file mode 100644 index 00000000..90752b5d --- /dev/null +++ b/rotordc_one_optional_product_per_categ/views/assets.xml @@ -0,0 +1,15 @@ + + + +