# -*- coding: utf-8 -*- ############################################################################### # # Cybrosys Technologies Pvt. Ltd. # # Copyright (C) 2024-TODAY Cybrosys Technologies() # Author: Cybrosys Techno Solutions (odoo@cybrosys.com) # # You can modify it under the terms of the GNU AFFERO # GENERAL PUBLIC LICENSE (AGPL v3), Version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. # # You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE # (AGPL v3) along with this program. # If not, see . # ############################################################################### from odoo import http, fields from odoo.http import request from odoo.addons.payment import utils as payment_utils from odoo.tools.json import scriptsafe as json_scriptsafe from odoo.addons.website_sale.controllers import main class WebsiteSale(main.WebsiteSale): """Imported and recalled WebsiteSale class to Patch cart_update_json()""" @http.route() def cart_update_json( self, product_id, line_id=None, add_qty=None, set_qty=None, display=True, product_custom_attribute_values=None, no_variant_attribute_values=None, **kw ): """ This route is called : - When changing quantity from the cart. - When adding a product from the wishlist. - When adding a product to cart on the same page (without redirection). """ order = request.website.sale_get_order(force_create=True) if order.state != 'draft': request.website.sale_reset() if kw.get('force_create'): order = request.website.sale_get_order(force_create=True) else: return {} if product_custom_attribute_values: product_custom_attribute_values = json_scriptsafe.loads( product_custom_attribute_values) if no_variant_attribute_values: no_variant_attribute_values = json_scriptsafe.loads( no_variant_attribute_values) values = order._cart_update( product_id=product_id, line_id=line_id, add_qty=add_qty, set_qty=set_qty, product_custom_attribute_values=product_custom_attribute_values, no_variant_attribute_values=no_variant_attribute_values, **kw ) for line in order.order_line.filtered( lambda rec: rec.product_id.is_top_deal_product): line.update({"price_unit": line.product_id.offer_price}) values['notification_info'] = self._get_cart_notification_information( order, [values['line_id']]) values['notification_info']['warning'] = values.pop('warning', '') request.session['website_sale_cart_quantity'] = order.cart_quantity if not order.cart_quantity: request.website.sale_reset() return values values['cart_quantity'] = order.cart_quantity values['minor_amount'] = payment_utils.to_minor_currency_units( order.amount_total, order.currency_id ), if not display: return values values['cart_ready'] = order._is_cart_ready() values['website_sale.cart_lines'] = request.env[ 'ir.ui.view']._render_template( "website_sale.cart_lines", { 'website_sale_order': order, 'date': fields.Date.today(), 'suggested_products': order._cart_accessories() } ) values['website_sale.total'] = request.env[ 'ir.ui.view']._render_template( "website_sale.total", { 'website_sale_order': order, } ) return values