Skip to Content
Меню
Вам необхідно зареєструватися, щоб взаємодіяти зі спільнотою.
Це запитання позначене
1 Відповісти
123 Переглядів

in version 18, when dealer click to add to cart button, stock not decrease automatically, admin should confirm it, how can we automize this process ( i don't want to click to confirm, it should done automatically )

Аватар
Відмінити
Найкраща відповідь

Got it! You want stock to decrease immediately when a dealer clicks "Add to Cart" in Odoo 18, without waiting for the admin to confirm the sale or delivery.


Why does this happen by default?

  • In Odoo's sales and eCommerce flow, stock is only reserved or decreased when the order is confirmed and delivery is validated .
  • Clicking "Add to Cart" just creates a quotation (draft sale order) ; stock does NOT decrease yet.
  • Stock moves happen when the sales order status moves to confirmed and delivery orders are processed.


To automate stock decrease at Add to Cart, you basically want:

  • The system to confirm the sale order automatically once added to cart (or shortly after).
  • Or, create and validate the delivery automatically.


Option 1: Auto-confirm the sales order immediately after adding to cart

You can customize the website sale module to automatically confirm the sale order right after the product is added to the cart.

Key points:

  • Override the add-to-cart controller to confirm the SO (sale order) right after creation.
  • Confirming the sale order will reserve the stock immediately.

Example: Auto confirm sales order on add to cart

Create a custom module and override the controller method for add to cart:

from odoo import http
from odoo.http import request

class WebsiteSaleAutoConfirm(http.Controller):

    @http.route(['/shop/cart/update'], type='json', auth="public", methods=['POST'], website=True)
    def cart_update_json(self, product_id, add_qty=1, set_qty=0, **kwargs):
        res = super(WebsiteSaleAutoConfirm, self).cart_update_json(product_id, add_qty=add_qty, set_qty=set_qty, **kwargs)
        
        sale_order = request.website.sale_get_order(force_create=True)
        if sale_order and sale_order.state == 'draft':
            # Auto confirm the sale order to reserve stock
            sale_order.action_confirm()
        
        return res

What's happening here?

  • After adding/updating the cart, the sale order (quotation) is confirmed automatically.
  • Confirmed orders reserve stock immediately, so stock decreases (or at least reserved).
  • You can also trigger delivery if needed in a similar way.

Option 2: Auto validate delivery after order confirmation

If you want to actually decrease stock (validate delivery), you need to auto-validate the picking.

You can extend the sale order confirmation to also create and validate the delivery picking automatically:

class SaleOrder(models.Model):
    _inherit = 'sale.order'

    def action_confirm(self):
        res = super().action_confirm()
        # Auto validate delivery picking
        for picking in self.picking_ids:
            if picking.state == 'assigned':
                picking.button_validate()
        return res

Important notes

  • Automatically confirming orders and validating delivery removes manual checks and may cause stock issues if stock is insufficient.
  • Make sure you have proper stock levels and your business flow supports this.
  • Consider adding warnings or notifications if stock is low or unavailable.

Summary

Step

What to do
Auto confirm SO Override add-to-cart controller to confirm SO
Auto validate picking Override action_confirm to validate delivery
Test thoroughly Check stock levels and order flow in your setup

If you want, I can help you write a full minimal custom module for this automation. Just let me know!


Thanks & Regards,

Email:-  contact@datainteger.com

Аватар
Відмінити