This commit adds hooks to give more flexibility and modularity. It allows inherited modules to give their own definition of the cart quantity and free quantity, which may be business specific (like for rentals). It also takes advantage of the definition of shop_warning in the website_sale module. This commit fixes a glitch when the wishlist message is displayed too fast, faster than the stock message. The message is removed by the promise in VariantMixin, _onCombinationChangeStock. task-2382027
29 lines
1.1 KiB
Python
29 lines
1.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.website_sale.controllers import main as website_sale_controller
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.exceptions import ValidationError
|
|
|
|
|
|
class PaymentPortal(website_sale_controller.PaymentPortal):
|
|
|
|
@http.route()
|
|
def shop_payment_transaction(self, *args, **kwargs):
|
|
""" Payment transaction override to double check cart quantities before
|
|
placing the order
|
|
"""
|
|
order = request.website.sale_get_order()
|
|
values = []
|
|
for line in order.order_line:
|
|
if line.product_id.type == 'product' and not line.product_id.allow_out_of_stock_order:
|
|
cart_qty, avl_qty = order._get_cart_and_free_qty(line=line)
|
|
if cart_qty > avl_qty:
|
|
line._set_shop_warning_stock(cart_qty, max(avl_qty, 0))
|
|
values.append(line.shop_warning)
|
|
if values:
|
|
raise ValidationError(' '.join(values))
|
|
return super().shop_payment_transaction(*args, **kwargs)
|