[FIX] website_sale_delivery: traceback when going back

Issue

	- Install eCommerce & Delivery Costs
	- Add a delivery method for US only
	- Publish the delivery method
	- Logout
	- Order something, select your delivery method
	  and pay with wire transfer
	- When it's done, click 2 times on the browser
	  back button

	Traceback

Cause

	When going back, the address is incorrect
	(public user address).

	So since you have 2 delivery methods and
	your address have only one, an assert
	cause a traceback

Solution

	This is the right behavior but I think
	it's better to give a clear error message
	instead of a traceback.

OPW-2243736

X-original-commit: 0222b727c143593debaf40a4ab54bda2f6b42213
This commit is contained in:
jvm-odoo
2020-05-25 07:31:05 +00:00
parent be54b82afd
commit 0e7102587e
2 changed files with 14 additions and 2 deletions
@@ -4,6 +4,7 @@
from odoo import http, _
from odoo.http import request
from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo.exceptions import UserError
class WebsiteSaleDelivery(WebsiteSale):
@@ -32,7 +33,10 @@ class WebsiteSaleDelivery(WebsiteSale):
@http.route(['/shop/carrier_rate_shipment'], type='json', auth='public', methods=['POST'], website=True)
def cart_carrier_rate_shipment(self, carrier_id, **kw):
order = request.website.sale_get_order(force_create=True)
assert int(carrier_id) in order._get_delivery_methods().ids, "unallowed carrier"
if not int(carrier_id) in order._get_delivery_methods().ids:
raise UserError(_('It seems that a delivery method is not compatible with your address. Please refresh the page and try again.'))
Monetary = request.env['ir.qweb.field.monetary']
res = {'carrier_id': carrier_id}
@@ -92,7 +92,15 @@ msgid "Free"
msgstr ""
#. module: website_sale_delivery
#: code:addons/website_sale_delivery/controllers/main.py:72
#: code:addons/website_sale_delivery/controllers/main.py:0
#, python-format
msgid ""
"It seems that a delivery method is not compatible with your address. Please "
"refresh the page and try again."
msgstr ""
#. module: website_sale_delivery
#: code:addons/website_sale_delivery/controllers/main.py:0
#, python-format
msgid ""
"No shipping method is available for your current order and shipping address."