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.

35 lines
1.5 KiB

3 years ago
3 years ago
  1. # © 2020 Le Filament (<http://www.le-filament.com>)
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  3. from odoo import http, _
  4. from odoo.http import request
  5. from odoo.addons.website_sale.controllers.main import WebsiteSale
  6. class WebsiteSale(WebsiteSale):
  7. @http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True, csrf=False)
  8. def cart_update(self, product_id, add_qty=1, set_qty=0, **kw):
  9. res = super(WebsiteSale, self).cart_update(product_id, add_qty, set_qty, **kw)
  10. if kw.get('consignes'):
  11. order = request.website.sale_get_order()
  12. # Recherche de la ligne de commande correspondant au produit référent
  13. line_id = order._cart_find_product_line(int(product_id))
  14. # Calcul du nombre de consignes correspondants
  15. # Recherche de la quantité produit
  16. temp_id = request.env['product.template'].sudo().browse(int(kw.get('product_template_id')))
  17. if temp_id.pack_ok:
  18. qty_consigne = add_qty
  19. else:
  20. qty_consigne = 0
  21. # Ajout de l'article consigné
  22. order._cart_update(
  23. product_id=int(kw.get('consignes')),
  24. add_qty=qty_consigne,
  25. linked_line_id=line_id.id,
  26. set_qty=0,
  27. product_custom_attribute_values=None,
  28. no_variant_attribute_values=None
  29. )
  30. return request.redirect("/shop/cart")