
Learn how to delete records from the Odoo database using the External API with the unlink method. Step-by-step guide for seamless remote record management.
Deleting data in Odoo with External API is simple. This can be beneficial. Especially when integrating Odoo with other apps. These apps require remote records management. You can commonly do this with Odoo's unlink method. This is accessed through XML-RPC or JSON-RPC protocols. In this text we will guide you. The guide is on how to delete records. It is safe. It is done efficiently.
Use External API for record deletion. It allows for integration with other applications. Cleanup tasks can automate. To manage data remotely, one does not need direct access to Odoo. For instance, you may need to delete outdated sales orders. Or you may want to erase customer records from an external application.
unlink method is Odoo’s standard for record deletion. While using External API you will call this method. You'll specify the IDs of the records you wish to remove.
Presented below is a Python sample. It illustrates how to delete records in the Odoo database with XML-RPC. Let's suggest that we desire to delete certain customer records. These records are in the model named res.partner.
import xmlrpc.client
# Connection details
url = "https://your-odoo-server.com"
db = "your_database_name"
username = "your_username"
password = "your_password"
# Connect to the Odoo server
common = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/common")
uid = common.authenticate(db, username, password, {})
# Create a connection to the object API
models = xmlrpc.client.ServerProxy(f"{url}/xmlrpc/2/object")
# Define the record IDs you want to delete (e.g., customer IDs)
record_ids = [1, 2, 3]
# Perform the delete operation using unlink
result = models.execute_kw(db, uid, password, 'res.partner', 'unlink', [record_ids])
if result:
print("Records deleted successfully.")
else:
print("Failed to delete records.")
In this example:
This script interfaces with server. It then authenticates user. Following this it triggers unlink method. Running on specified records in model. If the unlink method calls successfully, it deletes records.
Using Odoo’s External API is beneficial. It is used to delete records. This tool is helpful in maintaining data accuracy. It is also good for integrating with external applications. The unlink method is provided. It offers a simple way to manage records remotely. However one should be cautious. The goal is to ensure you don’t inadvertently delete critical data.
Your email address will not be published. Required fields are marked *