Skip to content

Commit 93197b1

Browse files
SirPyTechChionne27
authored andcommitted
[IMP] website_sale_product_reference_displayed: Show reference of variant
1 parent 15d0965 commit 93197b1

File tree

14 files changed

+239
-22
lines changed

14 files changed

+239
-22
lines changed

website_sale_product_reference_displayed/README.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
.. image:: https://odoo-community.org/readme-banner-image
2-
:target: https://odoo-community.org/get-involved?utm_source=readme
3-
:alt: Odoo Community Association
4-
51
=======================================
62
Display product reference in e-commerce
73
=======================================
@@ -17,7 +13,7 @@ Display product reference in e-commerce
1713
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
1814
:target: https://odoo-community.org/page/development-status
1915
:alt: Beta
20-
.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
2117
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
2218
:alt: License: AGPL-3
2319
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github
@@ -35,6 +31,8 @@ Display product reference in e-commerce
3531
This module extends the ``website_sale`` views to display the product's full
3632
display name, with its product reference included.
3733

34+
The Internal Reference is also shown explicitly in the product details and automatically updated when the chosen variant changes.
35+
3836
**Table of contents**
3937

4038
.. contents::
@@ -76,6 +74,9 @@ Contributors
7674

7775
* David Vidal
7876
* Carlos Roca
77+
* `PyTech <https://www.pytech.it>`_:
78+
79+
* Simone Rubino <simone.rubino@pytech.it>
7980

8081
Maintainers
8182
~~~~~~~~~~~
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import controllers

website_sale_product_reference_displayed/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@
1010
"application": False,
1111
"installable": True,
1212
"depends": ["website_sale"],
13-
"data": ["views/website_sale_views.xml"],
13+
"data": ["views/assets.xml", "views/website_sale_views.xml"],
1414
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
2+
3+
from . import variant
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Copyright 2025 Simone Rubino - PyTech
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import http
5+
from odoo.http import request
6+
7+
from odoo.addons.website_sale.controllers.variant import WebsiteSaleVariantController
8+
9+
10+
class WebsiteSaleReferenceDisplayed(WebsiteSaleVariantController):
11+
@http.route()
12+
def get_combination_info_website(
13+
self, product_template_id, product_id, combination, add_qty, **kw
14+
):
15+
res = super().get_combination_info_website(
16+
product_template_id, product_id, combination, add_qty, **kw
17+
)
18+
variant_id = res.get("product_id")
19+
if variant_id:
20+
variant = request.env["product.product"].browse(variant_id)
21+
variant_reference = variant.default_code or None
22+
else:
23+
variant_reference = None
24+
res["variant_reference"] = variant_reference
25+
return res

website_sale_product_reference_displayed/readme/CONTRIBUTORS.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22

33
* David Vidal
44
* Carlos Roca
5+
* `PyTech <https://www.pytech.it>`_:
6+
7+
* Simone Rubino <simone.rubino@pytech.it>
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
This module extends the ``website_sale`` views to display the product's full
22
display name, with its product reference included.
3+
4+
The Internal Reference is also shown explicitly in the product details and automatically updated when the chosen variant changes.

website_sale_product_reference_displayed/static/description/index.html

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
55
<meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6-
<title>README.rst</title>
6+
<title>Display product reference in e-commerce</title>
77
<style type="text/css">
88

99
/*
@@ -360,23 +360,19 @@
360360
</style>
361361
</head>
362362
<body>
363-
<div class="document">
363+
<div class="document" id="display-product-reference-in-e-commerce">
364+
<h1 class="title">Display product reference in e-commerce</h1>
364365

365-
366-
<a class="reference external image-reference" href="https://odoo-community.org/get-involved?utm_source=readme">
367-
<img alt="Odoo Community Association" src="https://odoo-community.org/readme-banner-image" />
368-
</a>
369-
<div class="section" id="display-product-reference-in-e-commerce">
370-
<h1>Display product reference in e-commerce</h1>
371366
<!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
372367
!! This file is generated by oca-gen-addon-readme !!
373368
!! changes will be overwritten. !!
374369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
375370
!! source digest: sha256:a465cf6f0086649a64e71d3d65a999dbaf16c19dce1ac1c6a8e9fbe3b6e605a6
376371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
377-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/license-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/e-commerce/tree/14.0/website_sale_product_reference_displayed"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/e-commerce-14-0/e-commerce-14-0-website_sale_product_reference_displayed"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/e-commerce/tree/14.0/website_sale_product_reference_displayed"><img alt="OCA/e-commerce" src="https://img.shields.io/badge/github-OCA%2Fe--commerce-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/e-commerce-14-0/e-commerce-14-0-website_sale_product_reference_displayed"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/e-commerce&amp;target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
378373
<p>This module extends the <tt class="docutils literal">website_sale</tt> views to display the product’s full
379374
display name, with its product reference included.</p>
375+
<p>The Internal Reference is also shown explicitly in the product details and automatically updated when the chosen variant changes.</p>
380376
<p><strong>Table of contents</strong></p>
381377
<div class="contents local topic" id="contents">
382378
<ul class="simple">
@@ -391,7 +387,7 @@ <h1>Display product reference in e-commerce</h1>
391387
</ul>
392388
</div>
393389
<div class="section" id="usage">
394-
<h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
390+
<h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
395391
<p>Just install and the products will be shown with their full display name.</p>
396392
<p>You can enable or disable for each template and website in the <em>Customize</em> frontend
397393
menu setting the <em>Display product reference</em> option on or off.</p>
@@ -400,33 +396,37 @@ <h2><a class="toc-backref" href="#toc-entry-1">Usage</a></h2>
400396
</div>
401397
</div>
402398
<div class="section" id="bug-tracker">
403-
<h2><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h2>
399+
<h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
404400
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/e-commerce/issues">GitHub Issues</a>.
405401
In case of trouble, please check there if your issue has already been reported.
406402
If you spotted it first, help us to smash it by providing a detailed and welcomed
407403
<a class="reference external" href="https://github.com/OCA/e-commerce/issues/new?body=module:%20website_sale_product_reference_displayed%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
408404
<p>Do not contact contributors directly about support or help with technical issues.</p>
409405
</div>
410406
<div class="section" id="credits">
411-
<h2><a class="toc-backref" href="#toc-entry-3">Credits</a></h2>
407+
<h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
412408
<div class="section" id="authors">
413-
<h3><a class="toc-backref" href="#toc-entry-4">Authors</a></h3>
409+
<h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
414410
<ul class="simple">
415411
<li>Tecnativa</li>
416412
</ul>
417413
</div>
418414
<div class="section" id="contributors">
419-
<h3><a class="toc-backref" href="#toc-entry-5">Contributors</a></h3>
415+
<h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
420416
<ul class="simple">
421417
<li><a class="reference external" href="https://www.tecnativa.com">Tecnativa</a>:<ul>
422418
<li>David Vidal</li>
423419
<li>Carlos Roca</li>
424420
</ul>
425421
</li>
422+
<li><a class="reference external" href="https://www.pytech.it">PyTech</a>:<ul>
423+
<li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;pytech.it">simone.rubino&#64;pytech.it</a>&gt;</li>
424+
</ul>
425+
</li>
426426
</ul>
427427
</div>
428428
<div class="section" id="maintainers">
429-
<h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
429+
<h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
430430
<p>This module is maintained by the OCA.</p>
431431
<a class="reference external image-reference" href="https://odoo-community.org">
432432
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
@@ -439,6 +439,5 @@ <h3><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h3>
439439
</div>
440440
</div>
441441
</div>
442-
</div>
443442
</body>
444443
</html>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
odoo.define("website_sale_product_reference_displayed.variant_mixin", function (
2+
require
3+
) {
4+
"use strict";
5+
6+
var publicWidget = require("web.public.widget");
7+
8+
publicWidget.registry.WebsiteSale.include({
9+
_onChangeCombination: function (ev, $parent, combination) {
10+
var result = this._super.apply(this, arguments);
11+
12+
// Dynamically update the variant_reference,
13+
// and hide it when empty
14+
var variant_reference = combination.variant_reference;
15+
var variant_reference_node = $parent
16+
.parents("#product_details")
17+
.find(".js_variant_reference_displayed")
18+
.first();
19+
if (variant_reference_node) {
20+
variant_reference_node.text(variant_reference).trigger("change");
21+
22+
var variant_reference_parent_node = variant_reference_node.parents(
23+
".js_variant_reference_displayed_parent"
24+
);
25+
if (variant_reference) {
26+
variant_reference_parent_node.removeClass("d-none");
27+
} else {
28+
variant_reference_parent_node.addClass("d-none");
29+
}
30+
}
31+
return result;
32+
},
33+
});
34+
});
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
odoo.define(
2+
"website_sale_product_reference_displayed.tour_dynamic_variant_reference",
3+
function (require) {
4+
"use strict";
5+
6+
var tour = require("web_tour.tour");
7+
8+
tour.register(
9+
"tour_dynamic_variant_reference",
10+
{
11+
test: true,
12+
url: "/shop?search=Test dynamic variant product template",
13+
},
14+
[
15+
{
16+
content: "Select Product",
17+
trigger:
18+
'.oe_product_cart a:containsExact("Test dynamic variant product template")',
19+
},
20+
{
21+
content: "Click on the second attribute value",
22+
trigger:
23+
'input[data-attribute_name="Test dynamic variant attribute"][data-value_name="Test dynamic variant value 1"]',
24+
},
25+
{
26+
content: "Wait for variant to be loaded",
27+
trigger: '.oe_price .oe_currency_value:contains("0.00")',
28+
// eslint-disable-next-line no-empty-function
29+
run: function () {},
30+
},
31+
{
32+
content: "Check the Internal Reference of the 1st variant",
33+
trigger: "span.js_variant_reference_displayed:contains(TESTREF1)",
34+
},
35+
{
36+
content: "Click on the second attribute value",
37+
trigger:
38+
'input[data-attribute_name="Test dynamic variant attribute"][data-value_name="Test dynamic variant value 2"]',
39+
},
40+
{
41+
content: "Wait for variant to be loaded",
42+
trigger: '.oe_price .oe_currency_value:contains("0.00")',
43+
// eslint-disable-next-line no-empty-function
44+
run: function () {},
45+
},
46+
{
47+
content: "Check the Internal Reference of the 2st variant",
48+
trigger: "span.js_variant_reference_displayed:contains(TESTREF2)",
49+
},
50+
]
51+
);
52+
}
53+
);

0 commit comments

Comments
 (0)