From 7384401e6365b9b00080154491cbbcc321d9719e Mon Sep 17 00:00:00 2001 From: "Lucas Perais (lpe)" Date: Mon, 9 Jul 2018 14:56:28 +0200 Subject: [PATCH] [FIX] website_sale_delivery: we shouldn't be able to pay if there is no delivery method Have some delivery method that do not apply to the country of the customer Before this commit, the customer could access the Pay now button and confirm the sale In v10.0 this was impossible as the retrieval of errors in python wiped out the variables that would make the xml element of the payment not to render In v11.0 this has changed in a more modular manner After this commit, we hide the element in html. OPW 1864744 Two use cases are dealt with: Should hide payment AND display errors when order contains deliverable product Should show payment AND not display errors when order contains only services (event tickets) Linked v10.0 PR #25692 closes #25679 --- addons/website_sale_delivery/controllers/main.py | 6 ++++-- .../views/website_sale_delivery_templates.xml | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/website_sale_delivery/controllers/main.py b/addons/website_sale_delivery/controllers/main.py index 70b3b446303..5a06774fcad 100644 --- a/addons/website_sale_delivery/controllers/main.py +++ b/addons/website_sale_delivery/controllers/main.py @@ -36,13 +36,14 @@ class WebsiteSaleDelivery(WebsiteSale): def _get_shop_payment_values(self, order, **kwargs): values = super(WebsiteSaleDelivery, self)._get_shop_payment_values(order, **kwargs) - if not order._get_delivery_methods(): + has_stockable_products = any(line.product_id.type in ['consu', 'product'] for line in order.order_line) + + if not order._get_delivery_methods() and has_stockable_products: values['errors'].append( (_('Sorry, we are unable to ship your order'), _('No shipping method is available for your current order and shipping address. ' 'Please contact us for more information.'))) - 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: order._remove_delivery_line() @@ -50,6 +51,7 @@ class WebsiteSaleDelivery(WebsiteSale): delivery_carriers = order._get_delivery_methods() values['deliveries'] = delivery_carriers.sudo() + values['delivery_has_stockable'] = has_stockable_products values['delivery_action_id'] = request.env.ref('delivery.action_delivery_carrier_form').id return values diff --git a/addons/website_sale_delivery/views/website_sale_delivery_templates.xml b/addons/website_sale_delivery/views/website_sale_delivery_templates.xml index 8b8aef3e478..d979fc722a4 100644 --- a/addons/website_sale_delivery/views/website_sale_delivery_templates.xml +++ b/addons/website_sale_delivery/views/website_sale_delivery_templates.xml @@ -57,6 +57,10 @@ + + + 'display: none!important' if not deliveries and delivery_has_stockable else '' +