diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_sale_coupon_delivery/controllers/main.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_sale_coupon_delivery/controllers/main.py')
| -rw-r--r-- | addons/website_sale_coupon_delivery/controllers/main.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/addons/website_sale_coupon_delivery/controllers/main.py b/addons/website_sale_coupon_delivery/controllers/main.py new file mode 100644 index 00000000..a5a76412 --- /dev/null +++ b/addons/website_sale_coupon_delivery/controllers/main.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +from odoo import http +from odoo.addons.website_sale_delivery.controllers.main import WebsiteSaleDelivery +from odoo.http import request + + +class WebsiteSaleCouponDelivery(WebsiteSaleDelivery): + + @http.route() + def update_eshop_carrier(self, **post): + Monetary = request.env['ir.qweb.field.monetary'] + result = super(WebsiteSaleCouponDelivery, self).update_eshop_carrier(**post) + order = request.website.sale_get_order() + free_shipping_lines = None + + if order: + order.recompute_coupon_lines() + order.validate_taxes_on_sales_order() + free_shipping_lines = order._get_free_shipping_lines() + + if free_shipping_lines: + currency = order.currency_id + amount_free_shipping = sum(free_shipping_lines.mapped('price_subtotal')) + result.update({ + 'new_amount_delivery': Monetary.value_to_html(0.0, {'display_currency': currency}), + 'new_amount_untaxed': Monetary.value_to_html(order.amount_untaxed, {'display_currency': currency}), + 'new_amount_tax': Monetary.value_to_html(order.amount_tax, {'display_currency': currency}), + 'new_amount_total': Monetary.value_to_html(order.amount_total, {'display_currency': currency}), + 'new_amount_order_discounted': Monetary.value_to_html(order.reward_amount - amount_free_shipping, {'display_currency': currency}), + }) + return result + + @http.route() + def cart_carrier_rate_shipment(self, carrier_id, **kw): + Monetary = request.env['ir.qweb.field.monetary'] + order = request.website.sale_get_order(force_create=True) + free_shipping_lines = order._get_free_shipping_lines() + # Avoid computing carrier price delivery is free (coupon). It means if + # the carrier has error (eg 'delivery only for Belgium') it will show + # Free until the user clicks on it. + if free_shipping_lines: + return { + 'carrier_id': carrier_id, + 'status': True, + 'is_free_delivery': True, + 'new_amount_delivery': Monetary.value_to_html(0.0, {'display_currency': order.currency_id}), + 'error_message': None, + } + return super(WebsiteSaleCouponDelivery, self).cart_carrier_rate_shipment(carrier_id, **kw) |
