Hi everyone 👋
Great question — this is a common concern, especially for inventory-driven businesses where products should not be archived if stock still exists.
✅ Goal
Prevent users from archiving a product if it has stock on hand, to avoid making it “disappear” from the system while still holding value in inventory.
🔐 Option 1: Use a Server Action or Automated Rule (no coding)
You can create a server action or automated action that prevents archiving if the qty_available is greater than 0:
-
Activate Developer Mode
-
Go to Settings > Technical > Automated Actions
-
Create a new action on model Product Template
-
Trigger on write
-
Add a condition like:
python
CopyEdit
if record.active == False and record.qty_available > 0:
raise UserError("This product has stock and cannot be archived.")
This blocks users from archiving products that still have quantities in stock.
🛠 Option 2: Custom Module (cleaner, more robust)
If you're comfortable with a bit of development, a custom module could override the unlink or write method for product.template and raise an error when trying to deactivate a product that has stock.
It’s more robust, especially if you need to add additional rules (e.g. checking stock across multiple warehouses, or also blocking archiving from list views).
🧠 Bonus Tip
If you use Odoo Studio, you can hide or disable the “archive” button conditionally — but this is more of a visual safeguard, and can be bypassed. It's best combined with one of the above methods for real protection.
Hope that helps! Let me know if you’d like help with the code snippet or Studio setup. 😊