From 2027cc5bd184ee32724f448715ccca3fabfdc7b5 Mon Sep 17 00:00:00 2001 From: mafo-odoo Date: Fri, 19 Aug 2022 07:30:04 +0000 Subject: [PATCH] [FIX] website_sale_delivery: a draft transaction prevents payment Steps to reproduce: - go to ecommerce try to pay with paypal and after stripe Current behavior: You get an error message Expected behavior: You have no error message Explanation: When /shop/update_carrier is called we check if there is a transaction that is not error or canceled mode and raise an error if this the case we should add the draft state to the list. We also add a condition so that the error can be raised only if the carrier was changed. opw-2956571 closes odoo/odoo#98584 X-original-commit: 863cc3998b0bb18a7557b312121ed8655150b1fc Signed-off-by: William Braeckman (wbr) --- addons/website_sale_delivery/controllers/main.py | 4 ++-- addons/website_sale_delivery/tests/test_controller.py | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/website_sale_delivery/controllers/main.py b/addons/website_sale_delivery/controllers/main.py index 532afeace15..dd6c1fcec42 100644 --- a/addons/website_sale_delivery/controllers/main.py +++ b/addons/website_sale_delivery/controllers/main.py @@ -26,8 +26,8 @@ class WebsiteSaleDelivery(WebsiteSale): def update_eshop_carrier(self, **post): order = request.website.sale_get_order() carrier_id = int(post['carrier_id']) - if order: - if any(tx.state not in ("canceled", "error") for tx in order.transaction_ids): + if order and carrier_id != order.carrier_id.id: + if any(tx.state not in ("canceled", "error", "draft") for tx in order.transaction_ids): raise UserError(_('It seems that there is already a transaction for your order, you can not change the delivery method anymore')) order._check_carrier_quotation(force_carrier_id=carrier_id) return self._update_website_sale_delivery_return(order, **post) diff --git a/addons/website_sale_delivery/tests/test_controller.py b/addons/website_sale_delivery/tests/test_controller.py index 67da8b8d81f..91fc865a72b 100644 --- a/addons/website_sale_delivery/tests/test_controller.py +++ b/addons/website_sale_delivery/tests/test_controller.py @@ -20,3 +20,10 @@ class TestWebsiteSaleDeliveryController(PaymentCommon): order.transaction_ids = self._create_transaction(flow='redirect', state='pending') with self.assertRaises(UserError): self.Controller.update_eshop_carrier(carrier_id=1) + + # test that changing the carrier while there is a draft transaction doesn't raise an error + def test_controller_change_carrier_when_draft_transaction(self): + with MockRequest(self.env, website=self.website): + order = self.website.sale_get_order(force_create=True) + order.transaction_ids = self._create_transaction(flow='redirect', state='draft') + self.Controller.update_eshop_carrier(carrier_id=1)