diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 0000000000..fb9418da61 --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-product_pricelist_item_uom_standard @ git+https://github.com/OCA/product-attribute.git@refs/pull/2364/head#subdirectory=product_pricelist_item_uom_standard diff --git a/website_sale_product_pricelist_item_uom/README.rst b/website_sale_product_pricelist_item_uom/README.rst new file mode 100644 index 0000000000..8826c27a46 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/README.rst @@ -0,0 +1,109 @@ +.. image:: https://odoo-community.org/readme-banner-image + :target: https://odoo-community.org/get-involved?utm_source=readme + :alt: Odoo Community Association + +======================================= +Website Sale Product Pricelist Item UoM +======================================= + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:17cd15ceeda4fffd614f9479d673ed5ef8c19cefaaf2ac97f8b96709e9dc2c2f + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |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/license-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/19.0/website_sale_product_pricelist_item_uom + :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-19-0/e-commerce-19-0-website_sale_product_pricelist_item_uom + :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=19.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module is a backport of the standard implementation Odoo introduces +in version 19.3, see +`odoo/odoo@d2648b1 `__. + +This module shows the price of each packaging on the eCommerce product +page. + +When a product is sold in several packagings, hovering a packaging +button displays the price of that packaging for the quantity currently +selected, so that customers can compare packagings without switching +between them. + +It is the eCommerce counterpart of +``product_pricelist_item_uom_standard``, which allows a pricelist rule +to be restricted to a specific packaging, and is installed automatically +when both that module and ``website_sale`` are installed. + +**Table of contents** + +.. contents:: + :local: + +Usage +===== + +1. Configure the packagings of a product and a pricelist rule per + packaging, as described in ``product_pricelist_item_uom_standard``. +2. Publish the product on the website. +3. Open the product page on the eCommerce: the packaging buttons are + displayed under the *Packaging* title. +4. Hover a packaging button: the price of that packaging for the + selected quantity is displayed next to the title, and disappears when + the pointer leaves the button. + +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 +------- + +* Camptocamp SA + +Contributors +------------ + +- `Camptocamp `__: + + - Ricardo Almeida Soares + +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_product_pricelist_item_uom/__init__.py b/website_sale_product_pricelist_item_uom/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/website_sale_product_pricelist_item_uom/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/website_sale_product_pricelist_item_uom/__manifest__.py b/website_sale_product_pricelist_item_uom/__manifest__.py new file mode 100644 index 0000000000..c7601b1b71 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/__manifest__.py @@ -0,0 +1,26 @@ +# Copyright 2026 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Website Sale Product Pricelist Item UoM", + "summary": "Show the price of each packaging on the eCommerce product page", + "version": "19.0.1.0.0", + "development_status": "Beta", + "category": "Website/Website", + "author": "Camptocamp SA, Odoo Community Association (OCA)", + "website": "https://github.com/OCA/e-commerce", + "license": "AGPL-3", + "depends": [ + "website_sale", + "product_pricelist_item_uom_standard", + ], + "data": [ + "views/variant_templates.xml", + ], + "assets": { + "web.assets_frontend": [ + "website_sale_product_pricelist_item_uom/static/src/js/interactions/**/*", + ], + }, + "installable": True, + "auto_install": True, +} diff --git a/website_sale_product_pricelist_item_uom/models/__init__.py b/website_sale_product_pricelist_item_uom/models/__init__.py new file mode 100644 index 0000000000..e8fa8f6bf1 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/models/__init__.py @@ -0,0 +1 @@ +from . import product_template diff --git a/website_sale_product_pricelist_item_uom/models/product_template.py b/website_sale_product_pricelist_item_uom/models/product_template.py new file mode 100644 index 0000000000..231462ebff --- /dev/null +++ b/website_sale_product_pricelist_item_uom/models/product_template.py @@ -0,0 +1,37 @@ +# Copyright 2026 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models +from odoo.http import request + + +class ProductTemplate(models.Model): + _inherit = "product.template" + + def _get_additionnal_combination_info( + self, product_or_template, quantity, uom, date, website + ): + combination_info = super()._get_additionnal_combination_info( + product_or_template, quantity, uom, date, website + ) + template = ( + product_or_template + if product_or_template._name == "product.template" + else product_or_template.product_tmpl_id + ) + if not template._has_multiple_uoms(): + return combination_info + pricelist = request.pricelist.with_context(**self.env.context) + combination_info["packaging_prices"] = {} + for product_uom in template._get_available_uoms(): + # Unit price expressed in the packaging UoM... + uom_price = pricelist._get_product_price( + product=product_or_template, quantity=quantity, uom=product_uom + ) + # ...converted back to the product base UoM, as displayed prices are. + combination_info["packaging_prices"][product_uom.id] = ( + product_uom._compute_price( + price=uom_price, to_unit=product_or_template.uom_id + ) + ) + return combination_info diff --git a/website_sale_product_pricelist_item_uom/pyproject.toml b/website_sale_product_pricelist_item_uom/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/website_sale_product_pricelist_item_uom/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/website_sale_product_pricelist_item_uom/readme/CONTRIBUTORS.md b/website_sale_product_pricelist_item_uom/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..c250877782 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ +- [Camptocamp](https://www.camptocamp.com): + - Ricardo Almeida Soares \<\> diff --git a/website_sale_product_pricelist_item_uom/readme/DESCRIPTION.md b/website_sale_product_pricelist_item_uom/readme/DESCRIPTION.md new file mode 100644 index 0000000000..f23697c19d --- /dev/null +++ b/website_sale_product_pricelist_item_uom/readme/DESCRIPTION.md @@ -0,0 +1,13 @@ +This module is a backport of the standard implementation Odoo introduces in +version 19.3, see +[odoo/odoo@d2648b1](https://github.com/odoo/odoo/commit/d2648b1d983927b5df7260a16d6d1d33c213ddeb#diff-5a563f36ffd028b0d8510c6d1339b097a5067a2247cc35c0f9bdd1fd0b5a0b0). + +This module shows the price of each packaging on the eCommerce product page. + +When a product is sold in several packagings, hovering a packaging button +displays the price of that packaging for the quantity currently selected, +so that customers can compare packagings without switching between them. + +It is the eCommerce counterpart of `product_pricelist_item_uom_standard`, which +allows a pricelist rule to be restricted to a specific packaging, and is +installed automatically when both that module and `website_sale` are installed. diff --git a/website_sale_product_pricelist_item_uom/readme/USAGE.md b/website_sale_product_pricelist_item_uom/readme/USAGE.md new file mode 100644 index 0000000000..d68229346b --- /dev/null +++ b/website_sale_product_pricelist_item_uom/readme/USAGE.md @@ -0,0 +1,8 @@ +1. Configure the packagings of a product and a pricelist rule per packaging, + as described in `product_pricelist_item_uom_standard`. +2. Publish the product on the website. +3. Open the product page on the eCommerce: the packaging buttons are displayed + under the *Packaging* title. +4. Hover a packaging button: the price of that packaging for the selected + quantity is displayed next to the title, and disappears when the pointer + leaves the button. diff --git a/website_sale_product_pricelist_item_uom/static/description/index.html b/website_sale_product_pricelist_item_uom/static/description/index.html new file mode 100644 index 0000000000..dbdecb99b3 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/static/description/index.html @@ -0,0 +1,458 @@ + + + + + +README.rst + + + +
+ + + +Odoo Community Association + +
+

Website Sale Product Pricelist Item UoM

+ +

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

+

This module is a backport of the standard implementation Odoo introduces +in version 19.3, see +odoo/odoo@d2648b1.

+

This module shows the price of each packaging on the eCommerce product +page.

+

When a product is sold in several packagings, hovering a packaging +button displays the price of that packaging for the quantity currently +selected, so that customers can compare packagings without switching +between them.

+

It is the eCommerce counterpart of +product_pricelist_item_uom_standard, which allows a pricelist rule +to be restricted to a specific packaging, and is installed automatically +when both that module and website_sale are installed.

+

Table of contents

+ +
+

Usage

+
    +
  1. Configure the packagings of a product and a pricelist rule per +packaging, as described in product_pricelist_item_uom_standard.
  2. +
  3. Publish the product on the website.
  4. +
  5. Open the product page on the eCommerce: the packaging buttons are +displayed under the Packaging title.
  6. +
  7. Hover a packaging button: the price of that packaging for the +selected quantity is displayed next to the title, and disappears when +the pointer leaves the button.
  8. +
+
+
+

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

+
    +
  • Camptocamp SA
  • +
+
+
+

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_product_pricelist_item_uom/static/src/js/interactions/website_sale.esm.js b/website_sale_product_pricelist_item_uom/static/src/js/interactions/website_sale.esm.js new file mode 100644 index 0000000000..4764f91bb2 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/static/src/js/interactions/website_sale.esm.js @@ -0,0 +1,97 @@ +import {patch} from "@web/core/utils/patch"; +import {WebsiteSale} from "@website_sale/interactions/website_sale"; + +patch(WebsiteSale.prototype, { + /** + * Override to listen to the packaging buttons. + * + * @override + */ + setup() { + super.setup(...arguments); + Object.assign(this.dynamicContent, { + ".o_packaging_button": { + "t-on-mouseenter": this.onHoverPackagingButton, + "t-on-mouseleave": this.onMouseLeavePackagingButton, + "t-on-click": this.onMouseLeavePackagingButton, + }, + }); + }, + + /** + * Display the price of the hovered packaging, when it differs from the + * price of the currently selected one. + * + * @param {MouseEvent} ev + */ + onHoverPackagingButton(ev) { + const parent = ev.target.closest(".js_product"); + const priceEl = parent.querySelector('p[name="packaging_price_value"]'); + if (!priceEl) { + return; + } + const hoveredPrice = parseFloat( + ev.target.querySelector('input[name="uom_id"]').dataset.packagingPrice + ); + const currentPrice = this._getUoMPrice(parent); + if (Number(currentPrice.toFixed(2)) === Number(hoveredPrice.toFixed(2))) { + return; + } + priceEl.querySelector(".oe_currency_value").textContent = + this._priceToStr(hoveredPrice); + parent.querySelector('span[name="packaging_price"]').classList.remove("d-none"); + }, + + /** + * Restore the price of the selected packaging. + * + * @param {MouseEvent} ev + */ + onMouseLeavePackagingButton(ev) { + const parent = ev.target.closest(".js_product"); + parent.querySelector('span[name="packaging_price"]')?.classList.add("d-none"); + }, + + /** + * Override to refresh the packaging prices on combination change. + * + * @override + */ + _onChangeCombination(ev, parent, combination) { + const res = super._onChangeCombination(...arguments); + if ("packaging_prices" in combination) { + this._handlePackagingInfo(parent, combination); + } + return res; + }, + + /** + * Return the price of the currently selected packaging. + * + * @private + * @param {Element} element + * @returns {float} + */ + _getUoMPrice(element) { + return parseFloat( + element.querySelector('input[name="uom_id"]:checked')?.dataset + .packagingPrice + ); + }, + + /** + * Store the price of each packaging on its own radio input. + * + * @private + * @param {Element} parent + * @param {Object} combination + */ + _handlePackagingInfo(parent, combination) { + Object.entries(combination.packaging_prices).forEach(([uomId, price]) => { + const el = parent.querySelector(`input[name="uom_id"]#uom-${uomId}`); + if (el) { + el.dataset.packagingPrice = price; + } + }); + }, +}); diff --git a/website_sale_product_pricelist_item_uom/tests/__init__.py b/website_sale_product_pricelist_item_uom/tests/__init__.py new file mode 100644 index 0000000000..8811bb5459 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/tests/__init__.py @@ -0,0 +1 @@ +from . import test_product_template diff --git a/website_sale_product_pricelist_item_uom/tests/test_product_template.py b/website_sale_product_pricelist_item_uom/tests/test_product_template.py new file mode 100644 index 0000000000..4af54859f5 --- /dev/null +++ b/website_sale_product_pricelist_item_uom/tests/test_product_template.py @@ -0,0 +1,70 @@ +# Copyright 2026 Camptocamp SA (https://www.camptocamp.com). +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.fields import Command +from odoo.tests.common import tagged + +from odoo.addons.website_sale.tests.common import MockRequest, WebsiteSaleCommon + + +@tagged("post_install", "-at_install") +class TestProductTemplatePackagingPrices(WebsiteSaleCommon): + @classmethod + def setUpClass(cls): + super().setUpClass() + # ``_has_multiple_uoms`` is only true when the packagings feature is on. + cls.env.ref("base.group_user").implied_ids |= cls.env.ref("uom.group_uom") + cls._enable_pricelists() + + cls.product_tmpl = cls.env["product.template"].create( + { + "name": "Test Packaging Product", + "list_price": 100.0, + "uom_id": cls.uom_unit.id, + "uom_ids": [Command.link(cls.uom_pack_6.id)], + "is_published": True, + } + ) + cls.env["product.pricelist.item"].create( + [ + { + "pricelist_id": cls.pricelist.id, + "applied_on": "1_product", + "product_tmpl_id": cls.product_tmpl.id, + "compute_price": "fixed", + "fixed_price": 10.0, + "uom_id": cls.uom_unit.id, + }, + { + "pricelist_id": cls.pricelist.id, + "applied_on": "1_product", + "product_tmpl_id": cls.product_tmpl.id, + "compute_price": "fixed", + "fixed_price": 8.0, + "uom_id": cls.uom_pack_6.id, + }, + ] + ) + + def test_combination_info_packaging_prices(self): + """Each packaging price is returned, expressed in the product base UoM.""" + with MockRequest( + self.env, website=self.website, website_sale_current_pl=self.pricelist.id + ): + combination_info = self.product_tmpl._get_combination_info() + + packaging_prices = combination_info["packaging_prices"] + self.assertEqual(set(packaging_prices), {self.uom_unit.id, self.uom_pack_6.id}) + self.assertEqual(packaging_prices[self.uom_unit.id], 10.0) + self.assertEqual(packaging_prices[self.uom_pack_6.id], 8.0) + + def test_combination_info_without_packaging(self): + """Products sold in a single UoM get no packaging price.""" + self.product_tmpl.uom_ids = [Command.clear()] + + with MockRequest( + self.env, website=self.website, website_sale_current_pl=self.pricelist.id + ): + combination_info = self.product_tmpl._get_combination_info() + + self.assertNotIn("packaging_prices", combination_info) diff --git a/website_sale_product_pricelist_item_uom/views/variant_templates.xml b/website_sale_product_pricelist_item_uom/views/variant_templates.xml new file mode 100644 index 0000000000..e1175e97fb --- /dev/null +++ b/website_sale_product_pricelist_item_uom/views/variant_templates.xml @@ -0,0 +1,41 @@ + + + + + + +