main.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # -*- coding: utf-8 -*-
  2. from odoo import http
  3. from odoo.addons.website_sale_delivery.controllers.main import WebsiteSaleDelivery
  4. from odoo.http import request
  5. class WebsiteSaleLoyaltyDelivery(WebsiteSaleDelivery):
  6. @http.route()
  7. def update_eshop_carrier(self, **post):
  8. Monetary = request.env['ir.qweb.field.monetary']
  9. result = super().update_eshop_carrier(**post)
  10. order = request.website.sale_get_order()
  11. free_shipping_lines = None
  12. if order:
  13. order._update_programs_and_rewards()
  14. order.validate_taxes_on_sales_order()
  15. free_shipping_lines = order._get_free_shipping_lines()
  16. if free_shipping_lines:
  17. currency = order.currency_id
  18. amount_free_shipping = sum(free_shipping_lines.mapped('price_subtotal'))
  19. result.update({
  20. 'new_amount_delivery': Monetary.value_to_html(0.0, {'display_currency': currency}),
  21. 'new_amount_untaxed': Monetary.value_to_html(order.amount_untaxed, {'display_currency': currency}),
  22. 'new_amount_tax': Monetary.value_to_html(order.amount_tax, {'display_currency': currency}),
  23. 'new_amount_total': Monetary.value_to_html(order.amount_total, {'display_currency': currency}),
  24. 'new_amount_order_discounted': Monetary.value_to_html(order.reward_amount - amount_free_shipping, {'display_currency': currency}),
  25. 'new_amount_total_raw': order.amount_total,
  26. })
  27. return result
  28. @http.route()
  29. def cart_carrier_rate_shipment(self, carrier_id, **kw):
  30. Monetary = request.env['ir.qweb.field.monetary']
  31. order = request.website.sale_get_order(force_create=True)
  32. free_shipping_lines = order._get_free_shipping_lines()
  33. # Avoid computing carrier price delivery is free (coupon). It means if
  34. # the carrier has error (eg 'delivery only for Belgium') it will show
  35. # Free until the user clicks on it.
  36. if free_shipping_lines:
  37. return {
  38. 'carrier_id': carrier_id,
  39. 'status': True,
  40. 'is_free_delivery': True,
  41. 'new_amount_delivery': Monetary.value_to_html(0.0, {'display_currency': order.currency_id}),
  42. 'error_message': None,
  43. }
  44. return super().cart_carrier_rate_shipment(carrier_id, **kw)