How to update Odoo 15+16+17+18 with AI automatically

Complete guide to migrate Odoo using OpenCode and OCA OpenUpgrade scripts

Introduction

Updating Odoo from one major version to another (15 to 16, 16 to 17, 17 to 18) is a complex process that requires careful planning. In this comprehensive tutorial, we will learn how to use OpenCode combined with the OCA OpenUpgrade framework to automate the migration process of your entire Odoo platform.

The Odoo Community Association (OCA) provides the OpenUpgrade project, an open-source migration tool that includes scripts for migrating data and modules between Odoo versions.

Dejo por aquí el vídeo de la práctica de actualización en directo: https://youtu.be/N2FdzVa9PDg


Prerequisites

  • A server with Ubuntu (recommended by Odoo)
  • Root or sudo access
  • Python 3.10 or higher
  • PostgreSQL 12 or higher
  • Git installed
  • Odoo source code for both source and target versions

Part 1: Install OpenCode on the Server

1.1 One-Line Installation (Recommended)

The easiest way to install OpenCode on Ubuntu is with a single command:

curl -fsSL https://opencode.ai/install | bash

This command will automatically:

  • Detect your system architecture
  • Download the latest OpenCode version
  • Install it to the appropriate location
  • Configure your PATH environment variable

1.2 Verify Installation

After installation, verify OpenCode is working:

# Verify installation
opencode --version

# Check available commands
opencode --help

1.3 Configure OpenCode

Create the OpenCode configuration file:

# Create configuration directory
mkdir -p ~/.config/opencode

# Create configuration file
cat > ~/.config/opencode/config.json << 'EOF'
{
  "defaultModel": "anthropic/claude-3-5-sonnet-20241022",
  "theme": "dark"
}
EOF

Part 2: Install OCA OpenUpgrade Framework

The OCA OpenUpgrade framework is the foundation for migrating Odoo databases. It contains migration scripts developed by the OCA community.

2.1 Clone OpenUpgrade Repository

# Create a directory for OpenUpgrade
sudo mkdir -p /opt/odoo-migration
cd /opt/odoo-migration

# Clone OpenUpgrade for your target version (e.g., 17.0)
sudo git clone -b 17.0 https://github.com/OCA/OpenUpgrade.git
cd OpenUpgrade

# Install Python dependencies
sudo pip3 install -r requirements.txt

2.2 Download Migration Scripts

The migration scripts are located in the openupgrade_scripts module. Download them for your specific version path:

# Scripts are already included in the OpenUpgrade clone
# Location: /opt/odoo-migration/OpenUpgrade/openupgrade_scripts/scripts/

# Each module has its own migration directory:
# openupgrade_scripts/scripts/[module_name]/[version]/

# Example structure:
# scripts/account/pre-migration.py
# scripts/account/post-migration.py

Part 3: Prepare Your Odoo Installation

3.1 Create Database Backup

CRITICAL: Always backup your database before any migration!

# Backup your database
pg_dump -U odoo -F c your_database_name > backup_$(date +%Y%m%d_%H%M%S).dump

# Or backup with filestore
mkdir -p /tmp/odoo_backup
cp -r /path/to/odoo/filestore/* /tmp/odoo_backup/
pg_dump -U odoo -F c your_database_name > /tmp/odoo_backup/database.dump

3.2 Configure Odoo for Migration

Update your Odoo configuration file to include OpenUpgrade:

# Edit your odoo.conf
cat > /opt/odoo17/config/odoo.conf << 'EOF'
[options]
admin_passwd = admin
db_host = localhost
db_port = 5432
db_user = odoo
db_password = odoo_password
addons_path = /opt/odoo17/odoo/addons,/opt/odoo17/custom-addons

# OpenUpgrade configuration
server_wide_modules = openupgrade_framework
upgrade_path = /opt/odoo-migration/OpenUpgrade/openupgrade_scripts/scripts/

# Important: Set log level for debugging
log_level = info
logfile = /var/log/odoo/odoo.log
EOF

Part 4: Migration Process with OpenCode

4.1 Navigate to Your Custom Addons Directory

# Go to your custom addons directory
cd /opt/odoo17/custom-addons/

# Or your module directory
cd /opt/odoo17/custom-addons/your_module/

4.2 Launch OpenCode

# Start OpenCode
opencode

4.3 Use the OCA Migration Prompt

Copy and paste this prompt into OpenCode for migrating with OCA scripts:

Eres un experto en migración de Odoo utilizando los scripts de OpenUpgrade de la OCA (Odoo Community Association). Tu tarea es migrar la plataforma completa Odoo desde la versión [ORIGEN] a la versión [DESTINO].

CONTEXTO OCA:
- OpenUpgrade: https://github.com/OCA/OpenUpgrade
- Scripts de migración: openupgrade_scripts/scripts/
- Framework: openupgrade_framework

Pasos a seguir:

1. ANÁLISIS PREVIO:
   - Lee los archivos de análisis en openupgrade_scripts/scripts/[module]/openupgrade_analysis.txt
   - Identifica los breaking changes documentados
   - Revisa los scripts de migración existentes

2. CONFIGURACIÓN DEL ENTORNO:
   - Asegúrate de que openupgrade_framework está en server_wide_modules
   - Configura el upgrade_path en odoo.conf
   - Verifica que los scripts están en la ruta correcta

3. MIGRACIÓN DE MÓDULOS ESTÁNDAR:
   - Ejecuta Odoo con --update=all para forzar actualización
   - Los scripts pre-migration.py se ejecutan antes de cargar el módulo
   - Los scripts post-migration.py se ejecutan después de cargar el módulo

4. MIGRACIÓN DE MÓDULOS PERSONALIZADOS:
   - Analiza los cambios en modelos Python
   - Actualiza las decoraciones de campos (@api.depends, @api.onchange)
   - Modifica las vistas XML según la nueva API
   - Crea scripts de migración si es necesario

5. MIGRACIÓN DE DATOS:
   - Usa las funciones de openupgrade: migrate_sequences(), rename_columns(), etc.
   - Mapea valores de selection fields si cambiaron
   - Actualiza referencias XML

6. VERIFICACIÓN:
   - Ejecuta el test suite
   - Verifica integridad de datos
   - Prueba todas las funcionalidades críticas

HERRAMIENTAS OCA DISPONIBLES:
- openupgrade.wrap(): Para envolver funciones obsoletas
- openupgrade.set_defaults(): Para establecer valores por defecto
- openupgrade.rename_columns(): Para renombrar columnas
- openupgrade.add_columns(): Para añadir columnas faltantes
- openupgrade.drop_columns(): Para eliminar columnas obsoletas

IMPORTANTE:
- Documenta todos los cambios realizados
- Mantén la compatibilidad con datos existentes
- Usa los scripts de OCA como referencia
- Contribuye de vuelta a la comunidad si es posible

4.4 Execute the Migration

Run the migration using OpenUpgrade:

# Stop Odoo service first
sudo systemctl stop odoo

# Run migration with OpenUpgrade
/opt/odoo17/odoo/odoo-bin -c /opt/odoo17/config/odoo.conf \
  -d your_database_name \
  -u all \
  --stop-after-init

# Check logs for errors
tail -f /var/log/odoo/odoo.log

Part 5: OCA Resources and Credits

The OCA (Odoo Community Association) is a non-profit organization that provides thousands of open-source modules and the OpenUpgrade framework. Please support their work!

OCA Links

OCA Social Media

Support OCA

Consider becoming a member or sponsor of the OCA to support the development of free modules and migration tools:

Conclusion

Using OpenCode with OCA OpenUpgrade scripts provides a powerful combination for migrating Odoo platforms. The OCA community has developed comprehensive migration scripts that handle the complexity of data transformation between versions, while OpenCode helps you understand and adapt the code for your specific needs.

Remember to always backup your database, test in development first, and contribute back to the OCA community when possible.

Propuesta de plantilla de presupuestos
Nueva plantilla para el envío de presupuestos o propuestas a clientes