You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.7 KiB
39 lines
1.7 KiB
# © 2020 Le Filament (<http://www.le-filament.com>)
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
|
|
|
|
from odoo import http, _
|
|
from odoo.http import request
|
|
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
|
|
|
|
|
class WebsiteSale(WebsiteSale):
|
|
|
|
@http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True, csrf=False)
|
|
def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
|
|
res = super(WebsiteSale, self).cart_update(product_id, add_qty, set_qty, **kw)
|
|
|
|
if kw.get('consignes'):
|
|
order = request.website.sale_get_order()
|
|
# Recherche de la ligne de commande correspondant au produit référent
|
|
line_id = order._cart_find_product_line(int(product_id))
|
|
|
|
# Recherche du produit consigne correspondant
|
|
consigne_id = request.env['product.product'].sudo().search([
|
|
('product_tmpl_id', '=', int(kw.get('consignes')))], limit=1)
|
|
# Calcul du nombre de consignes correspondants
|
|
# Recherche de la quantité produit
|
|
temp_id = request.env['product.template'].sudo().browse(int(kw.get('product_template_id')))
|
|
if temp_id.pack_ok:
|
|
qty_consigne = add_qty
|
|
else:
|
|
qty_consigne = 0
|
|
# Ajout de l'article consigné
|
|
order._cart_update(
|
|
product_id=consigne_id.id,
|
|
add_qty=qty_consigne,
|
|
linked_line_id=line_id.id,
|
|
set_qty=0,
|
|
product_custom_attribute_values=None,
|
|
no_variant_attribute_values=None
|
|
)
|
|
return request.redirect("/shop/cart")
|