| 1 |
|
| 2 |
|
| 3 |
from functools import partial |
| 4 |
|
| 5 |
from odoo.http import request, route |
| 6 |
|
| 7 |
from odoo.addons.payment import utils as payment_utils |
| 8 |
from odoo.addons.website_sale.controllers.delivery import Delivery |
| 9 |
|
| 10 |
|
| 11 |
class WebsiteSaleLoyaltyDelivery(Delivery): |
| 12 |
|
| 13 |
@route() |
| 14 |
def express_checkout_process_delivery_address(self, partial_delivery_address): |
| 15 |
"""Override of `website.sale` to include delivery discount if any.""" |
| 16 |
res = super().express_checkout_process_delivery_address(partial_delivery_address) |
| 17 |
order_sudo = request.cart |
| 18 |
if free_shipping_lines := order_sudo._get_free_shipping_lines(): |
| 19 |
res['delivery_discount_minor_amount'] = payment_utils.to_minor_currency_units( |
| 20 |
sum(free_shipping_lines.mapped('price_total')), order_sudo.currency_id |
| 21 |
) |
| 22 |
return res |
| 23 |
|
| 24 |
def _order_summary_values(self, order, **post): |
| 25 |
to_html = partial( |
| 26 |
request.env['ir.qweb.field.monetary'].value_to_html, |
| 27 |
options={'display_currency': order.currency_id}, |
| 28 |
) |
| 29 |
res = super()._order_summary_values(order, **post) |
| 30 |
free_shipping_lines = order._get_free_shipping_lines() |
| 31 |
if free_shipping_lines: |
| 32 |
shipping_discount = sum(free_shipping_lines.mapped('price_total')) |
| 33 |
res['amount_delivery_discounted'] = to_html(shipping_discount) |
| 34 |
res['delivery_discount_minor_amount'] = payment_utils.to_minor_currency_units( |
| 35 |
shipping_discount, order.currency_id |
| 36 |
) |
| 37 |
res['discount_reward_amounts'] = [ |
| 38 |
to_html(sum(lines.mapped('price_subtotal'))) |
| 39 |
for reward, lines in order.order_line.grouped('reward_id').items() |
| 40 |
if reward.reward_type == 'discount' |
| 41 |
] |
| 42 |
return res |