[FIX] website_sale_delivery: carrier selection is now working and faster

Since f963500a9f, users of the ecommerce
were able to select carriers even if they actually were not shipping to
their address.
Also, using an integrated carrier (eg: Fedex) caused a crash at the
payment page.

With this commit, delivery price is now computed only on the payment
page and when selected.
Editing the cart after selecting a delivery method will now be much
faster, since delivery prices are not recomputed anywhere else than on
the payment page

(we also fix minor CSS and JS issues)
This commit is contained in:
Richard Mathot
2017-07-20 12:00:58 +02:00
parent fa3e89064a
commit f830f14d98
5 changed files with 15 additions and 18 deletions
+1 -1
View File
@@ -1257,7 +1257,7 @@
<div id="wrap">
<div class="container oe_website_sale">
<div class="row">
<div class="col-lg-8 col-sm-9">
<div class="col-md-offset-2 col-lg-8 col-sm-9">
<t t-foreach="errors" t-as="error">
<div class="alert alert-danger" t-if="error">
<h4>
@@ -44,8 +44,14 @@ class WebsiteSaleDelivery(WebsiteSale):
has_stockable_products = any(line.product_id.type in ['consu', 'product'] for line in order.order_line)
if has_stockable_products:
if order.carrier_id and not order.delivery_rating_success:
values['errors'].append(
(_("Ouch, you cannot choose this carrier!"),
_("%s does not ship to your address, please choose another one.") % order.carrier_id.name))
order._remove_delivery_line()
delivery_carriers = order._get_delivery_methods()
values['deliveries'] = delivery_carriers.sudo().with_context(order_id=order.id)
values['deliveries'] = delivery_carriers.sudo()
values['delivery_action_id'] = request.env.ref('delivery.action_delivery_carrier_form').id
return values
@@ -2,8 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import logging
from odoo import api, fields, models, _
from odoo.exceptions import ValidationError
from odoo import api, fields, models
_logger = logging.getLogger(__name__)
@@ -61,7 +60,8 @@ class SaleOrder(models.Model):
self.write({'carrier_id': carrier.id})
if carrier:
self.get_delivery_price()
self.set_delivery_line()
if self.delivery_rating_success:
self.set_delivery_line()
else:
self._remove_delivery_line()
@@ -85,8 +85,4 @@ class SaleOrder(models.Model):
values = super(SaleOrder, self)._cart_update(product_id, line_id, add_qty, set_qty, **kwargs)
if add_qty or set_qty is not None:
for sale_order in self:
self._check_carrier_quotation()
return values
@@ -1,3 +1,4 @@
'use strict';
$(document).ready(function () {
// When choosing an delivery carrier, update the quotation and the acquirers
@@ -11,7 +12,7 @@ $(document).ready(function () {
var value = $(this).val();
var $provider_free = $("select[name='country_id']:not(.o_provider_restricted), select[name='state_id']:not(.o_provider_restricted)");
var $provider_restricted = $("select[name='country_id'].o_provider_restricted, select[name='state_id'].o_provider_restricted");
if (value == 0) {
if (value === 0) {
// Ship to the same address : only show shipping countries available for billing
$provider_free.hide().attr('disabled', true);
$provider_restricted.show().attr('disabled', false).change();
@@ -25,20 +25,14 @@
<xpath expr="//div[@id='payment_method']" position="before">
<div t-if="deliveries" class="col-md-12 row" id="delivery_carrier">
<div class="col-lg-7 col-sm-8">
<h4>Choose a delivery method</h4>
<h4>Choose a delivery method <i class="fa fa-question text-muted" title="Delivery price will be updated after choosing a new delivery method" aria-hidden="true"></i></h4>
<ul class="list-unstyled">
<li t-foreach="deliveries" t-as="delivery">
<div id="delivery_method">
<label>
<input t-att-value="delivery.id" type="radio" name="delivery_type"
t-att-checked="order.carrier_id and order.carrier_id.id == delivery.id and 'checked' or False" disabled="1"/>
t-att-checked="order.carrier_id and order.carrier_id.id == delivery.id and 'checked' or False"/>
<abbr t-att-title="delivery.website_description"><span t-field="delivery.name"/></abbr>
<span class="badge" t-field="delivery.price"
t-options='{
"widget": "monetary",
"from_currency": delivery.product_id.company_id.currency_id,
"display_currency": website_sale_order.currency_id
}'/>
<div t-field="delivery.website_description" class="text-muted"/>
</label>
</div>