diff --git a/website_sale_product_assortment/__manifest__.py b/website_sale_product_assortment/__manifest__.py index dc59ad57eb..e35a94aaea 100644 --- a/website_sale_product_assortment/__manifest__.py +++ b/website_sale_product_assortment/__manifest__.py @@ -3,7 +3,7 @@ { "name": "eCommerce product assortment", "summary": "Use product assortments to display products available on e-commerce.", - "version": "16.0.1.1.0", + "version": "18.0.1.1.0", "development_status": "Beta", "license": "AGPL-3", "category": "Website", @@ -16,8 +16,8 @@ "assets": { "web.assets_frontend": [ "website_sale_product_assortment/static/src/xml/*.xml", - "website_sale_product_assortment/static/src/js/variant_mixin.js", - "website_sale_product_assortment/static/src/js/assortment_list_preview.js", + "website_sale_product_assortment/static/src/js/variant_mixin.esm.js", + "website_sale_product_assortment/static/src/js/assortment_list_preview.esm.js", ], "web.assets_tests": [ "website_sale_product_assortment/static/src/js/no_purchase_tour.js", diff --git a/website_sale_product_assortment/controllers/variant.py b/website_sale_product_assortment/controllers/variant.py index f80dcf5044..1989b0fe27 100644 --- a/website_sale_product_assortment/controllers/variant.py +++ b/website_sale_product_assortment/controllers/variant.py @@ -4,10 +4,12 @@ from odoo import _, http from odoo.http import request -from odoo.addons.sale.controllers.variant import VariantController +from odoo.addons.sale.controllers.product_configurator import ( + SaleProductConfiguratorController, +) -class WebsiteSaleVariantController(VariantController): +class WebsiteSaleVariantController(SaleProductConfiguratorController): @http.route( ["/sale/get_info_assortment_preview"], type="json", diff --git a/website_sale_product_assortment/models/product_template.py b/website_sale_product_assortment/models/product_template.py index 3f96895afd..5f1a467ad9 100644 --- a/website_sale_product_assortment/models/product_template.py +++ b/website_sale_product_assortment/models/product_template.py @@ -38,7 +38,6 @@ def _get_combination_info( combination=False, product_id=False, add_qty=1, - pricelist=False, parent_combination=False, only_template=False, ): @@ -46,7 +45,6 @@ def _get_combination_info( combination=combination, product_id=product_id, add_qty=add_qty, - pricelist=pricelist, parent_combination=parent_combination, only_template=only_template, ) diff --git a/website_sale_product_assortment/static/src/js/assortment_list_preview.esm.js b/website_sale_product_assortment/static/src/js/assortment_list_preview.esm.js new file mode 100644 index 0000000000..109e233956 --- /dev/null +++ b/website_sale_product_assortment/static/src/js/assortment_list_preview.esm.js @@ -0,0 +1,47 @@ +import core from "web.core"; + +var WebsiteSaleProductAssortment = { + selector: "#products_grid", + + start: function () { + return $.when.apply($, [ + this._super.apply(this, arguments), + this.render_assortments(), + ]); + }, + render_assortments: function () { + const $products = $(".o_wsale_product_grid_wrapper"); + const product_dic = {}; + $products.each(function () { + product_dic[this.querySelector("a img").src.split("/")[6]] = this; + }); + const product_ids = Object.keys(product_dic).map(Number); + return this._rpc({ + route: "/sale/get_info_assortment_preview", + params: {product_template_ids: product_ids}, + }).then((product_values) => { + for (const product of product_values) { + this.render_product_assortment(product_dic[product.id], product); + } + }); + }, + render_product_assortment: function (product_info, product) { + $(product_info) + .find(".product_price") + .append( + $( + core.qweb.render( + "website_sale_product_assortment.product_availability", + { + message_unavailable: product.message_unavailable, + product_template_id: product.id, + } + ) + ).get(0) + ); + + $(product_info).find(".fa-shopping-cart").parent().addClass("disabled"); + }, +}; + +export default WebsiteSaleProductAssortment; diff --git a/website_sale_product_assortment/static/src/js/assortment_list_preview.js b/website_sale_product_assortment/static/src/js/assortment_list_preview.js deleted file mode 100644 index be239b0a3b..0000000000 --- a/website_sale_product_assortment/static/src/js/assortment_list_preview.js +++ /dev/null @@ -1,50 +0,0 @@ -odoo.define("website_sale_product_assortment.assortment_preview", function (require) { - "use strict"; - - const publicWidget = require("web.public.widget"); - const core = require("web.core"); - - publicWidget.registry.WebsiteSaleProductAssortment = publicWidget.Widget.extend({ - selector: "#products_grid", - - start: function () { - return $.when.apply($, [ - this._super.apply(this, arguments), - this.render_assortments(), - ]); - }, - render_assortments: function () { - const $products = $(".o_wsale_product_grid_wrapper"); - const product_dic = {}; - $products.each(function () { - product_dic[this.querySelector("a img").src.split("/")[6]] = this; - }); - const product_ids = Object.keys(product_dic).map(Number); - return this._rpc({ - route: "/sale/get_info_assortment_preview", - params: {product_template_ids: product_ids}, - }).then((product_values) => { - for (const product of product_values) { - this.render_product_assortment(product_dic[product.id], product); - } - }); - }, - render_product_assortment: function (product_info, product) { - $(product_info) - .find(".product_price") - .append( - $( - core.qweb.render( - "website_sale_product_assortment.product_availability", - { - message_unavailable: product.message_unavailable, - product_template_id: product.id, - } - ) - ).get(0) - ); - - $(product_info).find(".fa-shopping-cart").parent().addClass("disabled"); - }, - }); -}); diff --git a/website_sale_product_assortment/static/src/js/variant_mixin.esm.js b/website_sale_product_assortment/static/src/js/variant_mixin.esm.js new file mode 100644 index 0000000000..5fbaaa9af2 --- /dev/null +++ b/website_sale_product_assortment/static/src/js/variant_mixin.esm.js @@ -0,0 +1,52 @@ +// Copyright 2021 Tecnativa - Carlos Roca +// License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +import {QWeb} from "web.core"; +import VariantMixin from "@website_sale/js/sale_variant_mixin"; + +VariantMixin._onChangeCombinationAssortment = function (ev, $parent, combination) { + let product_id = 0; + if ($parent.find("input.product_id:checked").length) { + product_id = $parent.find("input.product_id:checked").val(); + } else { + product_id = $parent.find(".product_id").val(); + } + const isMainProduct = + combination.product_id && + ($parent.is(".js_main_product") || $parent.is(".main_product")) && + combination.product_id === parseInt(product_id); + if (!this.isWebsite || !isMainProduct) { + return; + } + $(".oe_website_sale") + .find("#message_unavailable_" + combination.product_template_id) + .remove(); + $("#product_full_assortment_description").remove(); + if (!combination.product_avoid_purchase) { + return; + } + $parent.find("#add_to_cart").addClass("disabled"); + $parent.find("#buy_now").addClass("disabled"); + $(".oe_website_sale") + .find("#product_option_block") + .prepend( + QWeb.render( + "website_sale_product_assortment.product_availability", + combination + ) + ); + if (combination.assortment_information) { + $("#product_detail").after( + "
" + + combination.assortment_information + + "
" + ); + } +}; + +VariantMixin._onChangeCombination = function (ev, $parent, combination) { + this._super.apply(this, arguments); + this._onChangeCombinationAssortment(ev, $parent, combination); +}; + +export default VariantMixin; diff --git a/website_sale_product_assortment/static/src/js/variant_mixin.js b/website_sale_product_assortment/static/src/js/variant_mixin.js deleted file mode 100644 index a19961a47b..0000000000 --- a/website_sale_product_assortment/static/src/js/variant_mixin.js +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright 2021 Tecnativa - Carlos Roca -// License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -odoo.define("website_sale_product_assortment.VariantMixin", function (require) { - "use strict"; - - var VariantMixin = require("sale.VariantMixin"); - var publicWidget = require("web.public.widget"); - var core = require("web.core"); - var QWeb = core.qweb; - - require("website_sale.website_sale"); - - VariantMixin._onChangeCombinationAssortment = function (ev, $parent, combination) { - let product_id = 0; - if ($parent.find("input.product_id:checked").length) { - product_id = $parent.find("input.product_id:checked").val(); - } else { - product_id = $parent.find(".product_id").val(); - } - const isMainProduct = - combination.product_id && - ($parent.is(".js_main_product") || $parent.is(".main_product")) && - combination.product_id === parseInt(product_id); - if (!this.isWebsite || !isMainProduct) { - return; - } - $(".oe_website_sale") - .find("#message_unavailable_" + combination.product_template_id) - .remove(); - $("#product_full_assortment_description").remove(); - if (!combination.product_avoid_purchase) { - return; - } - $parent.find("#add_to_cart").addClass("disabled"); - $parent.find("#buy_now").addClass("disabled"); - $(".oe_website_sale") - .find("#product_option_block") - .prepend( - QWeb.render( - "website_sale_product_assortment.product_availability", - combination - ) - ); - if (combination.assortment_information) { - $("#product_detail").after( - "
" + - combination.assortment_information + - "
" - ); - } - }; - - publicWidget.registry.WebsiteSale.include({ - /** - * Adds the stock checking to the regular _onChangeCombination method - * @override - */ - _onChangeCombination: function () { - this._super.apply(this, arguments); - VariantMixin._onChangeCombinationAssortment.apply(this, arguments); - }, - }); - - return VariantMixin; -}); diff --git a/website_sale_product_assortment/tests/test_ui.py b/website_sale_product_assortment/tests/test_ui.py index 30baa14de4..65d2fae7b1 100644 --- a/website_sale_product_assortment/tests/test_ui.py +++ b/website_sale_product_assortment/tests/test_ui.py @@ -18,41 +18,41 @@ def setUp(self): ) def test_01_ui_no_restriction(self): + partner_admin = self.env.ref("base.partner_admin") self.env["ir.filters"].create( { "name": "Test Assortment", "model_id": "product.product", "is_assortment": True, "domain": [("id", "!=", self.product.product_variant_id.id)], - "partner_domain": "[('id', '=', %s)]" - % self.env.ref("base.partner_admin").id, + "partner_domain": f"[('id', '=', {partner_admin.id})]", } ) self.start_tour("/shop", "test_assortment_with_no_restriction", login="admin") def test_02_ui_no_show(self): + partner_admin = self.env.ref("base.partner_admin") self.env["ir.filters"].create( { "name": "Test Assortment", "model_id": "product.product", "is_assortment": True, "domain": [("id", "!=", self.product.product_variant_id.id)], - "partner_domain": "[('id', '=', %s)]" - % self.env.ref("base.partner_admin").id, + "partner_domain": f"[('id', '=', {partner_admin.id})]", "website_availability": "no_show", } ) self.start_tour("/shop", "test_assortment_with_no_show", login="admin") def test_03_ui_no_purchase(self): + partner_admin = self.env.ref("base.partner_admin") self.env["ir.filters"].create( { "name": "Test Assortment", "model_id": "product.product", "is_assortment": True, "domain": [("id", "!=", self.product.product_variant_id.id)], - "partner_domain": "[('id', '=', %s)]" - % self.env.ref("base.partner_admin").id, + "partner_domain": f"[('id', '=', {partner_admin.id})]", "website_availability": "no_purchase", "message_unavailable": "Can't purchase", "assortment_information": """ diff --git a/website_sale_product_assortment/views/ir_filters_views.xml b/website_sale_product_assortment/views/ir_filters_views.xml index 10140fe35f..018522de31 100644 --- a/website_sale_product_assortment/views/ir_filters_views.xml +++ b/website_sale_product_assortment/views/ir_filters_views.xml @@ -18,11 +18,11 @@