-
-
Notifications
You must be signed in to change notification settings - Fork 500
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MIG] website_sale_secondary_unit: Migration to version 17.0
- Replaced the popover implementation with notifications, following the update in odoo/odoo#133990. - Removed the Unit from the displayed price. Previously, Odoo showed the price per unit, making it appropriate to include the UoM. However, as it now displays the total, the UoM is unnecessary.
- Loading branch information
1 parent
16499ce
commit a7b529a
Showing
15 changed files
with
377 additions
and
298 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ Contributors | |
- Sergio Teruel | ||
- Carlos Roca | ||
- Pilar Vargas | ||
- Carlos Lopez | ||
|
||
Maintainers | ||
----------- | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
- Sergio Teruel | ||
- Carlos Roca | ||
- Pilar Vargas | ||
- Carlos Lopez |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
..._unit/static/src/js/notification/add_to_cart_notification/add_to_cart_notification.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/** @odoo-module **/ | ||
/* Copyright 2025 Carlos Lopez - Tecnativa | ||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ | ||
|
||
import {AddToCartNotification} from "@website_sale/js/notification/add_to_cart_notification/add_to_cart_notification"; | ||
import {patch} from "@web/core/utils/patch"; | ||
|
||
patch(AddToCartNotification.prototype, { | ||
/** | ||
* Return the product summary based on the line information. | ||
* | ||
* If the line has a secondary unit of measure, | ||
* the product summary is computed based on the secondary unit of measure quantity and name, | ||
* | ||
* @param {Object} line - The line element for which to return the product summary. | ||
* @returns {String} - The product summary. | ||
*/ | ||
getProductSummary(line) { | ||
if (line.secondary_uom_name) { | ||
return ( | ||
line.secondary_uom_qty + | ||
" x " + | ||
line.secondary_uom_name + | ||
" " + | ||
line.name | ||
); | ||
} | ||
return super.getProductSummary(...arguments); | ||
}, | ||
}); | ||
|
||
const extendedShape = { | ||
...AddToCartNotification.props.lines.element.shape, | ||
secondary_uom_name: String, | ||
secondary_uom_qty: {type: Number, optional: true}, | ||
}; | ||
|
||
AddToCartNotification.props = { | ||
...AddToCartNotification.props, | ||
lines: { | ||
...AddToCartNotification.props.lines, | ||
element: { | ||
...AddToCartNotification.props.lines.element, | ||
shape: extendedShape, | ||
}, | ||
}, | ||
}; |
22 changes: 22 additions & 0 deletions
22
...sale_secondary_unit/static/src/js/notification/cart_notification/cart_notification.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** @odoo-module **/ | ||
/* Copyright 2025 Carlos Lopez - Tecnativa | ||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ | ||
|
||
import {CartNotification} from "@website_sale/js/notification/cart_notification/cart_notification"; | ||
|
||
const extendedShape = { | ||
...CartNotification.props.lines.element.shape, | ||
secondary_uom_name: String, | ||
secondary_uom_qty: {type: Number, optional: true}, | ||
}; | ||
|
||
CartNotification.props = { | ||
...CartNotification.props, | ||
lines: { | ||
...CartNotification.props.lines, | ||
element: { | ||
...CartNotification.props.lines.element, | ||
shape: extendedShape, | ||
}, | ||
}, | ||
}; |
137 changes: 137 additions & 0 deletions
137
website_sale_secondary_unit/static/src/js/website_sale_secondary_unit.esm.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/** @odoo-module **/ | ||
/* Copyright 2019 Sergio Teruel | ||
* Copyright 2025 Carlos Lopez - Tecnativa | ||
* License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). */ | ||
|
||
import "@website_sale/js/website_sale"; | ||
import VariantMixin from "@website_sale/js/sale_variant_mixin"; | ||
import publicWidget from "@web/legacy/js/public/public_widget"; | ||
|
||
publicWidget.registry.sale_secondary_unit = publicWidget.Widget.extend(VariantMixin, { | ||
selector: ".secondary-unit", | ||
// eslint-disable-next-line no-unused-vars | ||
init: function (parent, editableMode) { | ||
this._super.apply(this, arguments); | ||
this.$secondary_uom = null; | ||
this.$secondary_uom_qty = null; | ||
this.$product_qty = null; | ||
this.secondary_uom_qty = null; | ||
this.secondary_uom_factor = null; | ||
this.product_uom_factor = null; | ||
this.product_qty = null; | ||
}, | ||
start: function () { | ||
const _this = this; | ||
this.$secondary_uom = $("#secondary_uom"); | ||
this.$secondary_uom_qty = $(".secondary-quantity"); | ||
this.$product_qty = $(".quantity"); | ||
this._setValues(); | ||
this.$target.on( | ||
"change", | ||
".secondary-quantity", | ||
this._onChangeSecondaryUom.bind(this) | ||
); | ||
this.$target.on( | ||
"change", | ||
"#secondary_uom", | ||
this._onChangeSecondaryUom.bind(this) | ||
); | ||
this.$product_qty.on("change", null, this._onChangeProductQty.bind(this)); | ||
return this._super.apply(this, arguments).then(function () { | ||
_this._onChangeSecondaryUom(); | ||
}); | ||
}, | ||
_setValues: function () { | ||
this.secondary_uom_qty = Number(this.$target.find(".secondary-quantity").val()); | ||
this.secondary_uom_factor = Number( | ||
$("option:selected", this.$secondary_uom).data("secondary-uom-factor") | ||
); | ||
this.product_uom_factor = Number( | ||
$("option:selected", this.$secondary_uom).data("product-uom-factor") | ||
); | ||
this.product_qty = Number($(".quantity").val()); | ||
}, | ||
|
||
_onChangeSecondaryUom: function (ev) { | ||
if (!ev) { | ||
// HACK: Create a fake event to locate the form on "onChangeAddQuantity" | ||
// odoo method | ||
ev = jQuery.Event("fakeEvent"); | ||
ev.currentTarget = $(".form-control.quantity"); | ||
} | ||
this._setValues(); | ||
const factor = this.secondary_uom_factor * this.product_uom_factor; | ||
this.$product_qty.val(this.secondary_uom_qty * factor); | ||
this.onChangeAddQuantity(ev); | ||
}, | ||
_onChangeProductQty: function () { | ||
this._setValues(); | ||
const factor = this.secondary_uom_factor * this.product_uom_factor; | ||
this.$secondary_uom_qty.val(this.product_qty / factor); | ||
}, | ||
}); | ||
|
||
publicWidget.registry.sale_secondary_unit_cart = publicWidget.Widget.extend({ | ||
selector: ".oe_cart", | ||
// eslint-disable-next-line no-unused-vars | ||
init: function (parent, editableMode) { | ||
this._super.apply(this, arguments); | ||
this.$product_qty = null; | ||
this.secondary_uom_qty = null; | ||
this.secondary_uom_factor = null; | ||
this.product_uom_factor = null; | ||
this.product_qty = null; | ||
}, | ||
start: function () { | ||
var _this = this; | ||
this.$target.on( | ||
"change", | ||
"input.js_secondary_quantity[data-line-id]", | ||
function () { | ||
_this._onChangeSecondaryUom(this); | ||
} | ||
); | ||
}, | ||
_setValues: function (order_line) { | ||
this.$product_qty = this.$target.find( | ||
".quantity[data-line-id=" + order_line.dataset.lineId + "]" | ||
); | ||
this.secondary_uom_qty = Number(order_line.value); | ||
this.secondary_uom_factor = Number(order_line.dataset.secondaryUomFactor); | ||
this.product_uom_factor = Number(order_line.dataset.productUomFactor); | ||
}, | ||
_onChangeSecondaryUom: function (order_line) { | ||
this._setValues(order_line); | ||
const factor = this.secondary_uom_factor * this.product_uom_factor; | ||
this.$product_qty.val(this.secondary_uom_qty * factor); | ||
this.$product_qty.trigger("change"); | ||
}, | ||
}); | ||
|
||
publicWidget.registry.WebsiteSale.include({ | ||
_onChangeCombination: function (ev, $parent, combination) { | ||
const quantity = $parent.find(".css_quantity:not(.secondary_qty)"); | ||
const res = this._super(...arguments); | ||
if (combination.has_secondary_uom) { | ||
quantity.removeClass("d-inline-flex").addClass("d-none"); | ||
} else { | ||
quantity.removeClass("d-none").addClass("d-inline-flex"); | ||
} | ||
return res; | ||
}, | ||
_submitForm: function () { | ||
if ( | ||
!("secondary_uom_id" in this.rootProduct) && | ||
$(this.$target).find("#secondary_uom").length | ||
) { | ||
this.rootProduct.secondary_uom_id = $(this.$target) | ||
.find("#secondary_uom") | ||
.val(); | ||
this.rootProduct.secondary_uom_qty = $(this.$target) | ||
.find(".secondary-quantity") | ||
.val(); | ||
} | ||
|
||
this._super.apply(this, arguments); | ||
}, | ||
}); |
Oops, something went wrong.