[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
This commit is contained in:
Lucas Perais (lpe)
2018-07-10 11:51:00 +02:00
parent 24e01664d4
commit 7384401e63
2 changed files with 8 additions and 2 deletions
@@ -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
@@ -57,6 +57,10 @@
</a>
</div>
</xpath>
<!-- we shouldn't be able to pay if there is no way to deliver -->
<xpath expr="//div[@id='payment_method']" position="attributes">
<attribute name="t-att-style">'display: none!important' if not deliveries and delivery_has_stockable else ''</attribute>
</xpath>
</template>
<template id="portal_order_page_shipping_tracking" name="Shipping tracking on orders followup" inherit_id="website_sale_stock.portal_order_page_shipping">