From b40e3903f2c276085051eabee48e73e95f719b53 Mon Sep 17 00:00:00 2001 From: az-flectra Date: Mon, 9 Jul 2018 16:23:49 +0530 Subject: [PATCH] Added Upstream Patch for website_sale_delivery --- addons/website_sale_delivery/controllers/main.py | 15 +++++++++++---- addons/website_sale_delivery/models/sale_order.py | 1 + .../static/src/js/website_sale_delivery.js | 10 ++++++++++ .../views/website_sale_delivery_templates.xml | 2 +- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/addons/website_sale_delivery/controllers/main.py b/addons/website_sale_delivery/controllers/main.py index 9a17a4b0..cc27639e 100644 --- a/addons/website_sale_delivery/controllers/main.py +++ b/addons/website_sale_delivery/controllers/main.py @@ -67,8 +67,15 @@ class WebsiteSaleDelivery(WebsiteSale): return {'status': order.delivery_rating_success, 'error_message': order.delivery_message, 'carrier_id': carrier_id, - 'new_amount_delivery': float_repr(currency.round(order.delivery_price), currency.decimal_places), - 'new_amount_untaxed': order.amount_untaxed, - 'new_amount_tax': order.amount_tax, - 'new_amount_total': order.amount_total, + 'new_amount_delivery': self._format_amount(order.delivery_price, currency), + 'new_amount_untaxed': self._format_amount(order.amount_untaxed, currency), + 'new_amount_tax': self._format_amount(order.amount_tax, currency), + 'new_amount_total': self._format_amount(order.amount_total, currency), } + + def _format_amount(self, amount, currency): + fmt = "%.{0}f".format(currency.decimal_places) + lang = request.env['res.lang']._lang_get(request.env.context.get('lang') or 'en_US') + + return lang.format(fmt, currency.round(amount), grouping=True, monetary=True)\ + .replace(r' ', u'\N{NO-BREAK SPACE}').replace(r'-', u'\u2011') diff --git a/addons/website_sale_delivery/models/sale_order.py b/addons/website_sale_delivery/models/sale_order.py index 4d164308..42ac0c99 100644 --- a/addons/website_sale_delivery/models/sale_order.py +++ b/addons/website_sale_delivery/models/sale_order.py @@ -65,6 +65,7 @@ class SaleOrder(models.Model): carrier = delivery break self.write({'carrier_id': carrier.id}) + self._remove_delivery_line() if carrier: self.get_delivery_price() if self.delivery_rating_success: diff --git a/addons/website_sale_delivery/static/src/js/website_sale_delivery.js b/addons/website_sale_delivery/static/src/js/website_sale_delivery.js index ff6711bc..413ba007 100644 --- a/addons/website_sale_delivery/static/src/js/website_sale_delivery.js +++ b/addons/website_sale_delivery/static/src/js/website_sale_delivery.js @@ -27,6 +27,10 @@ flectra.define('website_sale_delivery.checkout', function (require) { else { console.error(result.error_message); $compute_badge.text(result.error_message); + $amount_delivery.text(result.new_amount_delivery); + $amount_untaxed.text(result.new_amount_untaxed); + $amount_tax.text(result.new_amount_tax); + $amount_total.text(result.new_amount_total); } }; @@ -40,6 +44,12 @@ flectra.define('website_sale_delivery.checkout', function (require) { var $carriers = $("#delivery_carrier input[name='delivery_type']"); $carriers.click(_onCarrierClick); + // Workaround to: + // - update the amount/error on the label at first rendering + // - prevent clicking on 'Pay Now' if the shipper rating fails + if ($carriers.length > 0) { + $carriers.filter(':checked').click(); + } /* Handle stuff */ $(".oe_website_sale select[name='shipping_id']").on('change', function () { 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 e993002b..04fc8240 100644 --- a/addons/website_sale_delivery/views/website_sale_delivery_templates.xml +++ b/addons/website_sale_delivery/views/website_sale_delivery_templates.xml @@ -3,7 +3,7 @@