Files
odoo_source/addons/website_sale_stock/controllers/main.py
T
Olivier Dony f763accc6f [FIX] website_sale_stock: fix incorrect override signature
The overridden payment_transaction() method needs to accept positional
arguments as well, otherwise it will break any other override that would
use positional arguments, and will fail with:

 payment_transaction() takes 1 positional argument but 6 were given

Introduced by 4d3f2fbdcda68d4f0e0bb3bb34d51e71d963621b via #51898

closes odoo/odoo#57890

X-original-commit: a4f5f811aba02cb29e344a576fbae9305481dd73
Signed-off-by: Olivier Dony (odo) <odo@openerp.com>
2020-09-16 16:19:33 +00:00

31 lines
1.4 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo.addons.website_sale.controllers.main import WebsiteSale
from odoo import http,_
from odoo.http import request
from odoo.exceptions import ValidationError
class WebsiteSaleStock(WebsiteSale):
@http.route()
def 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 line.product_id.inventory_availability in ['always', 'threshold']:
cart_qty = sum(order.order_line.filtered(lambda p: p.product_id.id == line.product_id.id).mapped('product_uom_qty'))
avl_qty = line.product_id.with_context(warehouse=order.warehouse_id.id).virtual_available
if cart_qty > avl_qty:
values.append(_(
'You ask for %(quantity)s products but only %(available_qty)s is available',
quantity=cart_qty,
available_qty=avl_qty if avl_qty > 0 else 0
))
if values:
raise ValidationError('. '.join(values) + '.')
return super(WebsiteSaleStock, self).payment_transaction(*args, **kwargs)