[FIX] website_sale_delivery: show correct fixed price

There was 2 issues regarding delivery price when the delivery was set to fixed
price and free over a certain amount.

1. On /shop/payment step, such deliveries would have the fixed price shown on
   the badge, even if the sale order amount exceed the free over threshold.
2. When clicking on a delivery carrier, it is supposed to compute all the SO
   costs (delivery, taxes..) and display them.
   The delivery price selector would try to get the 'badge.hidden' element
   which never exists for fixed prices. Thus, it would not update the delivery
   badge price.

Now:
1. If the free over threshold is met, we display 0$ instead of the fixed price
   by calling `rate_shipment`.
   Note that `rate_shipment` can't fail in case of a fixed rate (see method).
   The only failing case is if the customer country does not match the delivery
   allowed country, but such a flow is not possible as delivery shown during
   cart payment are already filtered by allowed countries.
2. The delivery value returned after clicking on the carrier is correctly
   updated on the badge.

Fixes #31502

closes odoo/odoo#32938

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Romain Derie
2019-05-06 14:51:43 +00:00
parent d47f0ddbe4
commit fb5015d5fc
2 changed files with 7 additions and 4 deletions
@@ -16,7 +16,7 @@ odoo.define('website_sale_delivery.checkout', function (require) {
var $amount_untaxed = $('#order_total_untaxed span.oe_currency_value');
var $amount_tax = $('#order_total_taxes span.oe_currency_value');
var $amount_total = $('#order_total span.oe_currency_value');
var $carrier_badge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .badge.hidden');
var $carrier_badge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .badge:not(.o_delivery_compute)');
var $compute_badge = $('#delivery_carrier input[name="delivery_type"][value=' + result.carrier_id + '] ~ .o_delivery_compute');
var $discount = $('#order_discounted');
@@ -34,9 +34,12 @@
<input t-att-value="delivery.id" t-att-id="'delivery_%i' % delivery.id" type="radio" name="delivery_type" t-att-checked="order.carrier_id and order.carrier_id.id == delivery.id and 'checked' or False" t-att-class="'hidden' if delivery_nb == 1 else ''"/>
<label class="label-optional" t-field="delivery.name" t-att-for="'delivery_%i' % delivery.id"/>
<t t-if="delivery.delivery_type == 'fixed'">
<span t-if="delivery.fixed_price > 0.0" class="badge pull-right"
t-field="delivery.fixed_price" t-options='{"widget": "monetary",
"from_currency": delivery.product_id.company_id.currency_id, "display_currency": website_sale_order.currency_id}'/>
<span t-if="delivery.fixed_price > 0.0" class="badge pull-right">
<t t-set="monetary_options" t-value='{"widget": "monetary",
"from_currency": delivery.product_id.company_id.currency_id, "display_currency": website_sale_order.currency_id}'/>
<t t-if="delivery.free_over" t-esc="delivery.rate_shipment(website_sale_order)['price']" t-options='monetary_options'/>
<t t-else="" t-esc="delivery.fixed_price" t-options='monetary_options'/>
</span>
<span t-else="" class="badge pull-right">Free</span>
</t>
<t t-else="">