[IMP] website_sale_coupon_delivery: consider free delivery

odoo/odoo#31857 retrieve asynchronously the delivery carrier price instead of having to
click on every one of them.
If the delivery is free thanks to coupon, the delivery price should be free and
no need to compute it.

Closes #31857
task-1867265
This commit is contained in:
Romain Derie
2019-04-02 08:00:34 +00:00
committed by Jeremy Kersten
parent 3bdf6cb358
commit b2b73b9295
@@ -23,3 +23,19 @@ class WebsiteSaleCouponDelivery(WebsiteSaleDelivery):
'new_amount_order_discounted': self._format_amount(order.reward_amount - amount_free_shipping, currency),
})
return result
@http.route()
def cart_carrier_rate_shipment(self, carrier_id, **kw):
order = request.website.sale_get_order(force_create=True)
free_shipping_lines = order._get_free_shipping_lines()
# Avoid computing carrier price delivery is free (coupon). It means if
# the carrier has error (eg 'delivery only for Belgium') it will show
# Free until the user clicks on it.
if free_shipping_lines:
return {
'carrier_id': carrier_id,
'status': True,
'new_amount_delivery': 0.0,
'error_message': None,
}
return super(WebsiteSaleCouponDelivery, self).cart_carrier_rate_shipment(carrier_id, **kw)