mirror of
https://github.com/bringout/oca-ocb-sale.git
synced 2026-04-27 22:12:07 +02:00
19.0 vanilla
This commit is contained in:
parent
79f83631d5
commit
73afc09215
6267 changed files with 1534193 additions and 1130106 deletions
|
|
@ -1,63 +1,29 @@
|
|||
# -*- 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.tools import email_re
|
||||
from odoo import http, _
|
||||
from odoo.http import request
|
||||
from odoo.exceptions import ValidationError
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
|
||||
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)
|
||||
from odoo import _
|
||||
from odoo.http import Controller, request, route
|
||||
from odoo.tools.mail import email_re
|
||||
|
||||
|
||||
class WebsiteSale(website_sale_controller.WebsiteSale):
|
||||
@http.route(['/shop/add/stock_notification'], type="json", auth="public", website=True)
|
||||
class WebsiteSaleStock(Controller):
|
||||
|
||||
@route('/shop/add/stock_notification', type='jsonrpc', auth='public', website=True)
|
||||
def add_stock_email_notification(self, email, product_id):
|
||||
# TDE FIXME: seems a bit open
|
||||
if not email_re.match(email):
|
||||
raise BadRequest(_("Invalid Email"))
|
||||
|
||||
product = request.env['product.product'].browse(int(product_id))
|
||||
partners = request.env['res.partner'].sudo()._mail_find_partner_from_emails([email], force_create=True)
|
||||
partner = partners[0]
|
||||
partner = request.env['mail.thread'].sudo()._partner_find_from_emails_single([email])
|
||||
|
||||
if not product._has_stock_notification(partner):
|
||||
product.sudo().stock_notification_partner_ids += partner
|
||||
|
||||
if request.website.is_public_user():
|
||||
request.session['product_with_stock_notification_enabled'] = request.session.get(
|
||||
'product_with_stock_notification_enabled',
|
||||
set()
|
||||
) | {product_id}
|
||||
request.session['product_with_stock_notification_enabled'] = list(
|
||||
set(request.session.get('product_with_stock_notification_enabled', []))
|
||||
| {product_id}
|
||||
)
|
||||
request.session['stock_notification_email'] = email
|
||||
|
||||
def _prepare_product_values(self, product, category='', search='', **kwargs):
|
||||
values = super()._prepare_product_values(product, category, search, **kwargs)
|
||||
# We need the user mail to prefill the back of stock notification, so we put it in the value that will be sent
|
||||
values['user_email'] = request.env.user.email or request.session.get('stock_notification_email', '')
|
||||
return values
|
||||
|
||||
class CustomerPortal(website_sale_controller.CustomerPortal):
|
||||
def _sale_reorder_get_line_context(self):
|
||||
return {
|
||||
**super()._sale_reorder_get_line_context(),
|
||||
'website_sale_stock_get_quantity': True,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue