[FIX] website_sale: manage access_point_address with Sendcloud

Steps to reproduce:
-------------------
- install website_sale and delivery_sendcloud module;
- create a shipping method (use Sendcloud provider);
- configure the integration with
"Mondial Relay Point Relais International 1-2kg";
- configure option with shipping rule and use location;
- on website create a new quotation with the pubic user;
- process the checkout;

(Check in backend the shipping weight)

- fill City and Zip Code fields with correct value
(example: Paris | 75011)

(- configure the company's country)

Issue:
------
[1.] If the shipping method is the only one, the locations are not displayed.
[2.] The delivery address is not the address of the chosen location.

Cause:
------
[2.] The method `update_eshop_carrier` is retriggered after update the `access_point_address` field.
The `access_point_address` is reset.

Solution:
---------
[1.] Show the option to choose a location if we only have one delivery method
(we are certain that the options should be displayed).
[2.] Use a parameter in the post request to instruct
not to reset the `access_point_address` field.

opw-3326139

closes odoo/odoo#125647

X-original-commit: 677bff31d3acdd05fff6567b693de78cff256ea2
Signed-off-by: Lefebvre Thomas (thle) <thle@odoo.com>
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Thomas Lefebvre (thle)
2023-06-19 19:17:08 +02:00
parent 7f6924e8fd
commit 2eb9c0708f
2 changed files with 8 additions and 6 deletions
+2 -1
View File
@@ -15,7 +15,8 @@ class WebsiteSaleDelivery(WebsiteSale):
@http.route(['/shop/update_carrier'], type='json', auth='public', methods=['POST'], website=True)
def update_eshop_carrier(self, **post):
order = request.website.sale_get_order()
order.access_point_address = {}
if not post.get('no_reset_access_point_address'):
order.access_point_address = {}
carrier_id = int(post['carrier_id'])
if order and carrier_id != order.carrier_id.id:
if any(tx.sudo().state not in ('cancel', 'error', 'draft') for tx in order.transaction_ids):
@@ -22,13 +22,13 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
* @override
*/
start: async function () {
const carriers = Array.from(document.querySelectorAll('input[name="delivery_type"]'));
this.carriers = Array.from(document.querySelectorAll('input[name="delivery_type"]'));
this.dp = new concurrency.DropPrevious();
// Workaround to:
// - update the amount/error on the label at first rendering
// - prevent clicking on 'Pay Now' if the shipper rating fails
if (carriers.length > 0) {
const carrierChecked = carriers.filter(e =>e.checked)
if (this.carriers.length > 0) {
const carrierChecked = this.carriers.filter(e =>e.checked)
if (carrierChecked.length === 0) {
const payButton = document.querySelector('button[name="o_payment_submit_button"]');
payButton? payButton.disabled = true : null;
@@ -38,7 +38,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
}
await this._getCurrentLocation();
await carriers.forEach(async (carrierInput) => {
await this.carriers.forEach(async (carrierInput) => {
this._showLoading((carrierInput));
await this._handleCarrierUpdateResult(carrierInput)
});
@@ -92,7 +92,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
}
const currentCarrierChecked = docCarrier.closest("li").getElementsByTagName("input")[0].checked;
const span = document.createElement("em");
if (!currentCarrierChecked) {
if (!currentCarrierChecked || this.carriers.length == 1) {
span.textContent = "select to see available Pick-Up Locations";
span.classList.add("text-muted");
}
@@ -389,6 +389,7 @@ publicWidget.registry.websiteSaleDelivery = publicWidget.Widget.extend({
route: '/shop/update_carrier',
params: {
'carrier_id': carrierId,
'no_reset_access_point_address': true,
},
})
this._setIsPayable(result.status)