diff --git a/website_sale_stock_list_preview/README.rst b/website_sale_stock_list_preview/README.rst new file mode 100644 index 0000000000..1582c519db --- /dev/null +++ b/website_sale_stock_list_preview/README.rst @@ -0,0 +1,93 @@ +=============================== +Website Sale Stock List Preview +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:ad9b3f022e290bed5f9302a30209a80d8e9175fe837651cd3afc30cc0a6821dd + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github + :target: https://github.com/OCA/e-commerce/tree/18.0/website_sale_stock_list_preview + :alt: OCA/e-commerce +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/e-commerce-18-0/e-commerce-18-0-website_sale_stock_list_preview + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module extends the functionality of e-Commerce to give the buyer +the information about the stock on the preview of the products. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +To use this module, you need to: + +- Edit some products on the option Availability of e-commerce +- Go to the shop on the website and active Add to Cart button on web + editor options. +- You can see on your products the results of the options that you had + choose. + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- ``Tecnativa ``\ \_\_: + + - Carlos Roca + - Sergio Teruel + - Carlos Dauden + - Pilar Vargas + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/e-commerce `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/website_sale_stock_list_preview/__init__.py b/website_sale_stock_list_preview/__init__.py new file mode 100644 index 0000000000..9613a24bd3 --- /dev/null +++ b/website_sale_stock_list_preview/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import controllers diff --git a/website_sale_stock_list_preview/__manifest__.py b/website_sale_stock_list_preview/__manifest__.py new file mode 100644 index 0000000000..5576f499d8 --- /dev/null +++ b/website_sale_stock_list_preview/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2020 Tecnativa - Carlos Roca +# Copyright 2020 Tecnativa - Sergio Teruel +# Copyright 2020 Tecnativa - Carlos Dauden +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Website Sale Stock List Preview", + "summary": "Show the stock of products on the product previews", + "version": "18.0.1.0.0", + "category": "Website", + "website": "https://github.com/OCA/e-commerce", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "installable": True, + "depends": ["website_sale_stock"], + "data": ["views/templates.xml"], + "assets": { + "web.assets_tests": [ + "/website_sale_stock_list_preview/static/src/tests/*.esm.js", + ], + }, +} diff --git a/website_sale_stock_list_preview/controllers/__init__.py b/website_sale_stock_list_preview/controllers/__init__.py new file mode 100644 index 0000000000..f43232f012 --- /dev/null +++ b/website_sale_stock_list_preview/controllers/__init__.py @@ -0,0 +1,3 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from . import main diff --git a/website_sale_stock_list_preview/controllers/main.py b/website_sale_stock_list_preview/controllers/main.py new file mode 100644 index 0000000000..5c36778e5f --- /dev/null +++ b/website_sale_stock_list_preview/controllers/main.py @@ -0,0 +1,39 @@ +# Copyright 2020 Tecnativa - Carlos Roca +# Copyright 2020 Tecnativa - Carlos Dauden +# Copyright 2025 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo.http import request + +from odoo.addons.website_sale.controllers.main import WebsiteSale + + +class WebsiteSaleStockListPreview(WebsiteSale): + def _get_additional_shop_values(self, values): + res = super()._get_additional_shop_values(values) + + products = values.get("products") or request.env["product.template"] + if not products: + return res + website = request.env["website"].get_current_website() + products_sudo = products.sudo().with_context( + warehouse=website.sudo().warehouse_id.id, + website_sale_stock_available=True, + ) + products_stock = {} + for tmpl in products_sudo: + if not tmpl.show_availability: + continue + variants = tmpl.product_variant_ids + products_stock[tmpl.id] = { + "product_template": tmpl.id, + "product_type": tmpl.type, + "free_qty": sum(variants.mapped("free_qty")), + "out_of_stock_message": tmpl.out_of_stock_message, + "allow_out_of_stock_order": tmpl.allow_out_of_stock_order, + "show_availability": tmpl.show_availability, + "available_threshold": tmpl.available_threshold, + "uom_name": tmpl.uom_name, + "uom_rounding": tmpl.uom_id.rounding, + } + res["products_stock"] = products_stock + return res diff --git a/website_sale_stock_list_preview/i18n/es.po b/website_sale_stock_list_preview/i18n/es.po new file mode 100644 index 0000000000..e69de29bb2 diff --git a/website_sale_stock_list_preview/i18n/it.po b/website_sale_stock_list_preview/i18n/it.po new file mode 100644 index 0000000000..73388557f6 --- /dev/null +++ b/website_sale_stock_list_preview/i18n/it.po @@ -0,0 +1,14 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" diff --git a/website_sale_stock_list_preview/i18n/website_sale_stock_list_preview.pot b/website_sale_stock_list_preview/i18n/website_sale_stock_list_preview.pot new file mode 100644 index 0000000000..78d58d53fe --- /dev/null +++ b/website_sale_stock_list_preview/i18n/website_sale_stock_list_preview.pot @@ -0,0 +1,13 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" diff --git a/website_sale_stock_list_preview/pyproject.toml b/website_sale_stock_list_preview/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_stock_list_preview/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_stock_list_preview/readme/CONTRIBUTORS.md b/website_sale_stock_list_preview/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..66bb7e9e2c --- /dev/null +++ b/website_sale_stock_list_preview/readme/CONTRIBUTORS.md @@ -0,0 +1,5 @@ +- `Tecnativa `__: + - Carlos Roca \ + - Sergio Teruel \ + - Carlos Dauden \ + - Pilar Vargas diff --git a/website_sale_stock_list_preview/readme/DESCRIPTION.md b/website_sale_stock_list_preview/readme/DESCRIPTION.md new file mode 100644 index 0000000000..02fea0ee0e --- /dev/null +++ b/website_sale_stock_list_preview/readme/DESCRIPTION.md @@ -0,0 +1,2 @@ +This module extends the functionality of e-Commerce to give the buyer the information +about the stock on the preview of the products. diff --git a/website_sale_stock_list_preview/readme/USAGE.md b/website_sale_stock_list_preview/readme/USAGE.md new file mode 100644 index 0000000000..059aa878c7 --- /dev/null +++ b/website_sale_stock_list_preview/readme/USAGE.md @@ -0,0 +1,5 @@ +To use this module, you need to: + +- Edit some products on the option Availability of e-commerce +- Go to the shop on the website and active Add to Cart button on web editor options. +- You can see on your products the results of the options that you had choose. diff --git a/website_sale_stock_list_preview/static/description/icon.png b/website_sale_stock_list_preview/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/website_sale_stock_list_preview/static/description/icon.png differ diff --git a/website_sale_stock_list_preview/static/description/index.html b/website_sale_stock_list_preview/static/description/index.html new file mode 100644 index 0000000000..b9e75e928f --- /dev/null +++ b/website_sale_stock_list_preview/static/description/index.html @@ -0,0 +1,442 @@ + + + + + +Website Sale Stock List Preview + + + +
+

Website Sale Stock List Preview

+ + +

Beta License: AGPL-3 OCA/e-commerce Translate me on Weblate Try me on Runboat

+

This module extends the functionality of e-Commerce to give the buyer +the information about the stock on the preview of the products.

+

Table of contents

+ +
+

Usage

+

To use this module, you need to:

+
    +
  • Edit some products on the option Availability of e-commerce
  • +
  • Go to the shop on the website and active Add to Cart button on web +editor options.
  • +
  • You can see on your products the results of the options that you had +choose.
  • +
+
+
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/e-commerce project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/website_sale_stock_list_preview/static/src/tests/tour.esm.js b/website_sale_stock_list_preview/static/src/tests/tour.esm.js new file mode 100644 index 0000000000..b6688628db --- /dev/null +++ b/website_sale_stock_list_preview/static/src/tests/tour.esm.js @@ -0,0 +1,64 @@ +/* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ +import {registry} from "@web/core/registry"; + +registry.category("web_tour.tours").add("website_sale_stock_list_preview", { + url: "/shop", + steps: () => [ + { + trigger: + ".o_wsale_product_information:has(.text-warning:contains('Only 30 Units left in stock.')) a:contains('Test Product 1')", + run: "click", + }, + { + trigger: + ".o_wsale_product_information:contains('Only 30 Units left in stock.')", + }, + { + trigger: "a[href='/shop']", + run: "click", + }, + { + trigger: + ".o_wsale_product_information:has(.text-warning:contains('Only 5 Units left in stock.')) a:contains('Test Product 3')", + run: "click", + }, + { + trigger: + ".o_wsale_product_information:contains('Only 5 Units left in stock.')", + }, + { + trigger: "a[href='/shop']", + run: "click", + }, + { + trigger: + ".o_wsale_product_information:contains('test') a:contains('Test Product 4')", + run: "click", + }, + { + trigger: "#product_details #out_of_stock_message:contains('test message')", + }, + { + trigger: "a[href='/shop']", + run: "click", + }, + { + trigger: "div:contains('Out of Stock') a:contains('Test Product 6')", + run: "click", + }, + { + trigger: "#out_of_stock_message:contains('Out of Stock')", + }, + { + trigger: "a[href='/shop']", + run: "click", + }, + { + trigger: "div:contains('Out of Stock') a:contains('Test Product 7')", + run: "click", + }, + { + trigger: "#out_of_stock_message:contains('Out of Stock')", + }, + ], +}); diff --git a/website_sale_stock_list_preview/tests/__init__.py b/website_sale_stock_list_preview/tests/__init__.py new file mode 100644 index 0000000000..6dab214ac8 --- /dev/null +++ b/website_sale_stock_list_preview/tests/__init__.py @@ -0,0 +1 @@ +from . import test_ui diff --git a/website_sale_stock_list_preview/tests/test_ui.py b/website_sale_stock_list_preview/tests/test_ui.py new file mode 100644 index 0000000000..f056b3c91d --- /dev/null +++ b/website_sale_stock_list_preview/tests/test_ui.py @@ -0,0 +1,124 @@ +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests.common import HttpCase, tagged + + +@tagged("post_install", "-at_install") +class UICase(HttpCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + product1 = cls.env["product.template"].create( + { + "name": "Test Product 1", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "is_storable": True, + "allow_out_of_stock_order": True, + "show_availability": True, + "available_threshold": 99999, + } + ) + product2 = cls.env["product.template"].create( + { + "name": "Test Product 2", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "is_storable": True, + "allow_out_of_stock_order": False, + "show_availability": True, + } + ) + product3 = cls.env["product.template"].create( + { + "name": "Test Product 3", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "is_storable": True, + "allow_out_of_stock_order": False, + "show_availability": True, + "available_threshold": 5, + } + ) + cls.env["product.template"].create( + { + "name": "Test Product 4", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "is_storable": True, + "out_of_stock_message": "test message", + } + ) + cls.env["product.template"].create( + { + "name": "Test Product 5", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "is_storable": True, + } + ) + cls.env["product.template"].create( + { + "name": "Test Product 6", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "is_storable": True, + "allow_out_of_stock_order": True, + "show_availability": True, + "out_of_stock_message": "Out of stock", + } + ) + cls.env["product.template"].create( + { + "name": "Test Product 7", + "is_published": True, + "website_sequence": 1, + "type": "consu", + "is_storable": True, + "allow_out_of_stock_order": False, + "show_availability": True, + } + ) + cls.env["stock.quant"].create( + [ + { + "product_id": product1.product_variant_id.id, + "location_id": cls.env.ref("stock.stock_location_stock").id, + "quantity": 30.0, + }, + { + "product_id": product2.product_variant_id.id, + "location_id": cls.env.ref("stock.stock_location_stock").id, + "quantity": 30.0, + }, + { + "product_id": product3.product_variant_id.id, + "location_id": cls.env.ref("stock.stock_location_stock").id, + "quantity": 5.0, + }, + ] + ) + cls.env.ref("website_sale.products_add_to_cart").active = True + # Ensure website lang is 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 = cls.env.ref("base.lang_en") + + def test_ui_website(self): + """Test frontend tour.""" + self.start_tour( + "/shop", "website_sale_stock_list_preview", login="admin", step_delay=100 + ) diff --git a/website_sale_stock_list_preview/views/templates.xml b/website_sale_stock_list_preview/views/templates.xml new file mode 100644 index 0000000000..b6e901ed4b --- /dev/null +++ b/website_sale_stock_list_preview/views/templates.xml @@ -0,0 +1,57 @@ + + + +