Prevent Accidental Database Deletion in Odoo18
Managing databases is an important part of working with Odoo 18. A database stores all the essential business information, including customer records, sales data, inventory details, accounting information, and much more. Because of this, deleting a database is considered a highly sensitive action.
In Odoo, administrators can delete databases using the database management page. Although the system asks for a master password before deletion, accidental clicks or human mistakes can still happen, especially when managing multiple databases in development, testing, or production environments.
Imagine accidentally deleting the wrong database with important business data. Recovering that information can be stressful, time-consuming, and sometimes even impossible without proper backups.
To reduce this risk, we developed a simple yet effective custom protection module for Odoo 18. This module adds extra safety steps before a database can be deleted. It introduces an unlock checkbox, disables the delete button by default, and displays a confirmation pop-up before the final action is performed.
The goal of this customization is simple: prevent accidental database deletion and improve user safety without modifying Odoo’s core system files.
In this blog, we will explain how the module works, how it is implemented, and why this small enhancement can make database management much safer in Odoo 18.
Why Database Protection Matters
Database deletion is a highly sensitive operation. In many organizations, developers and administrators frequently switch between staging, testing, and production databases. In such scenarios, even a small mistake can lead to major consequences.
Some common risks include:
- Accidentally deleting the wrong database
- Human error during testing
- Misclicks caused by repetitive administrative tasks
- Lack of visual warnings in the default interface
- Permanent loss of important business data
Although backups can help restore deleted information, recovery procedures often consume valuable time and resources. Adding preventive measures directly into the user interface is a far more practical approach.
This is where our custom database delete protection module becomes useful.
Features of the Database Delete Protection Module
The module introduces several safety-focused enhancements to the default Odoo database management interface.
Key Features
- Unlock the checkbox before deletion
- The delete button is disabled by default
- Confirmation pop-up before final deletion
- Additional visual warning system
- Lightweight implementation
- No modification to Odoo core files
These enhancements may seem small, but together they significantly reduce the chances of accidental database deletion.
Backend Implementation in Odoo 18
To implement this feature, we extended Odoo’s default database controller and injected a custom JavaScript file into the database management pages.
The backend logic is responsible for loading the protection script only where it is needed.
Controller File
The implementation starts with a custom controller:
db_delete_protection/controllers/main.py
The controller inherits from Odoo’s existing database controller:
from odoo import http
from odoo.addons.web.controllers.database import Database
import markupsafe
class DatabaseProtect(Database):
def _inject_js(self, response):
import time
version = int(time.time())
injection = f''
# If response is a werkzeug Response object
if hasattr(response, 'get_data') and hasattr(response, 'set_data'):
html_content = response.get_data(as_text=True)
if '



