From 9ae49f4219002cb9feca7a4ccfd04e12f14462d3 Mon Sep 17 00:00:00 2001 From: ernesto-garcia-tecnativa Date: Mon, 28 Aug 2023 00:50:15 -0600 Subject: [PATCH] [MIG] website_sale_stock_list_preview: Migration to 16.0 --- .../__manifest__.py | 2 +- .../controllers/main.py | 4 +- .../static/src/tests/tour.js | 2 - .../tests/test_ui.py | 49 ++++++++++--------- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/website_sale_stock_list_preview/__manifest__.py b/website_sale_stock_list_preview/__manifest__.py index f7180a39f7..672d1531a1 100644 --- a/website_sale_stock_list_preview/__manifest__.py +++ b/website_sale_stock_list_preview/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Website Sale Stock List Preview", "summary": "Show the stock of products on the product previews", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "category": "Website", "website": "https://github.com/OCA/e-commerce", "author": "Tecnativa, Odoo Community Association (OCA)", diff --git a/website_sale_stock_list_preview/controllers/main.py b/website_sale_stock_list_preview/controllers/main.py index 6f32e89c22..021da0b7a1 100644 --- a/website_sale_stock_list_preview/controllers/main.py +++ b/website_sale_stock_list_preview/controllers/main.py @@ -37,7 +37,9 @@ def get_combination_info_stock_preview(self, product_template_ids, **kw): "product_template": template.id, "product_type": template.type, "free_qty": sum(variants.mapped("free_qty")), - "cart_qty": sum(variants.mapped("cart_qty")), + "cart_qty": sum( + [product._get_cart_qty(current_website) for product in variants] + ), "out_of_stock_message": template.out_of_stock_message, "allow_out_of_stock_order": template.allow_out_of_stock_order, "show_availability": template.show_availability, diff --git a/website_sale_stock_list_preview/static/src/tests/tour.js b/website_sale_stock_list_preview/static/src/tests/tour.js index 40bfa31194..a54736eaf3 100644 --- a/website_sale_stock_list_preview/static/src/tests/tour.js +++ b/website_sale_stock_list_preview/static/src/tests/tour.js @@ -4,7 +4,6 @@ odoo.define("website_sale_stock_list_preview.tour", function (require) { "use strict"; var tour = require("web_tour.tour"); - var base = require("web_editor.base"); var steps = [ { @@ -119,7 +118,6 @@ odoo.define("website_sale_stock_list_preview.tour", function (require) { { url: "/shop", test: true, - wait_for: base.ready(), }, steps ); diff --git a/website_sale_stock_list_preview/tests/test_ui.py b/website_sale_stock_list_preview/tests/test_ui.py index 714ca1eec0..81cad92d37 100644 --- a/website_sale_stock_list_preview/tests/test_ui.py +++ b/website_sale_stock_list_preview/tests/test_ui.py @@ -5,9 +5,10 @@ @tagged("post_install", "-at_install") class UICase(HttpCase): - def setUp(self): - super().setUp() - product1 = self.env["product.template"].create( + @classmethod + def setUpClass(cls): + super().setUpClass() + product1 = cls.env["product.template"].create( { "name": "Test Product 1", "is_published": True, @@ -18,7 +19,7 @@ def setUp(self): "available_threshold": 99999, } ) - product2 = self.env["product.template"].create( + product2 = cls.env["product.template"].create( { "name": "Test Product 2", "is_published": True, @@ -28,7 +29,7 @@ def setUp(self): "show_availability": True, } ) - product3 = self.env["product.template"].create( + product3 = cls.env["product.template"].create( { "name": "Test Product 3", "is_published": True, @@ -39,7 +40,7 @@ def setUp(self): "available_threshold": 5, } ) - self.env["product.template"].create( + cls.env["product.template"].create( { "name": "Test Product 4", "is_published": True, @@ -48,7 +49,7 @@ def setUp(self): "out_of_stock_message": "test message", } ) - self.env["product.template"].create( + cls.env["product.template"].create( { "name": "Test Product 5", "is_published": True, @@ -56,7 +57,7 @@ def setUp(self): "type": "product", } ) - self.env["product.template"].create( + cls.env["product.template"].create( { "name": "Test Product 6", "is_published": True, @@ -67,7 +68,7 @@ def setUp(self): "out_of_stock_message": "Out of stock", } ) - self.env["product.template"].create( + cls.env["product.template"].create( { "name": "Test Product 7", "is_published": True, @@ -77,42 +78,42 @@ def setUp(self): "show_availability": True, } ) - self.env["stock.quant"].create( + cls.env["stock.quant"].create( [ { "product_id": product1.product_variant_id.id, - "location_id": self.env.ref("stock.stock_location_stock").id, + "location_id": cls.env.ref("stock.stock_location_stock").id, "quantity": 30.0, }, { "product_id": product2.product_variant_id.id, - "location_id": self.env.ref("stock.stock_location_stock").id, + "location_id": cls.env.ref("stock.stock_location_stock").id, "quantity": 30.0, }, { "product_id": product3.product_variant_id.id, - "location_id": self.env.ref("stock.stock_location_stock").id, + "location_id": cls.env.ref("stock.stock_location_stock").id, "quantity": 5.0, }, ] ) - self.env.ref("website_sale.products_add_to_cart").active = True + cls.env.ref("website_sale.products_add_to_cart").active = True # Ensure website lang is en_US. - website = self.env["website"].get_current_website() - wiz = self.env["base.language.install"].create({"lang": "en_US"}) + website = cls.env["website"].get_current_website() + en_us = ( + cls.env["res.lang"] + .with_context(active_test=False) + .search([("code", "=", "en_US")]) + ) + wiz = cls.env["base.language.install"].create({"lang_ids": en_us.ids}) wiz.website_ids = website wiz.lang_install() - website.default_lang_id = self.env.ref("base.lang_en") + website.default_lang_id = cls.env.ref("base.lang_en") def test_ui_website(self): """Test frontend tour.""" - tour = ( - "odoo.__DEBUG__.services['web_tour.tour']", + self.start_tour( + "/shop", "website_sale_stock_list_preview", - ) - self.browser_js( - url_path="/shop", - code="%s.run('%s')" % tour, - ready="%s.tours['%s'].ready" % tour, login="admin", )