feat(odoo): add support for automatic modules list update and improve database initialization checks

- Added `AUTO_UPDATE_MODULES_LIST` environment variable to trigger modules list update on container start
- Created new `update-modules-list` script to refresh available modules from addons path
- Introduced `check-database-initialized` utility script to verify database initialization status
- Refactored database initialization and module operations to use the new check
- Updated documentation to include new functionality and commands
- Added git-aggregator to requirements for improved dependency management
- Updated compose template and task scripts to support the new functionality
This commit is contained in:
Janik von Rotz committed 2025-09-26 14:04:42 +02:00
1 parent 1264e6d0ba
commit 8d30ebcdd6
13 files changed
+80 -42

No files matched your search

+2 -1
View File
@@ -67,7 +67,8 @@ services:
TEST_ADDONS_DIR: ${TEST_ADDONS_DIR}
TEST_INCLUDE: ${TEST_INCLUDE}
TEST_EXCLUDE: ${TEST_EXCLUDE}
AUTO_UPDATE_TRANSLATIONS: ${AUTO_UPDATE_TRANSLATIONS}
AUTO_UPDATE_TRANSLATIONS: "${AUTO_UPDATE_TRANSLATIONS}"
AUTO_UPDATE_MODULES_LIST: "${AUTO_UPDATE_MODULES_LIST}"
command: odoo --dev=all
ports:
- "${ODOO_PORT}:8069"
+8
View File
@@ -139,6 +139,7 @@ services:
TEST_INCLUDE: partner_firstname
TEST_EXCLUDE: partner_fax
AUTO_UPDATE_TRANSLATIONS: True
AUTO_UPDATE_MODULES_LIST: True
ports:
- "127.0.0.1:8069:8069"
volumes:
@@ -233,6 +234,12 @@ There is also the possiblity to update all modules:
docker compose exec odoo update-modules
```
Or update the modules list (refresh the list of available modules from the addons path):
```bash
docker compose exec odoo update-modules-list
```
For each installed module Odoo computes and stores a checksum in the database. The update modules script compares the checksum and updates all modules that have changed.
Updating module translations is simple:
@@ -406,6 +413,7 @@ The container uses [click-odoo-contrib](https://github.com/acsone/click-odoo-con
* `AUTO_UPDATE_MODULES` If enabled modules will updated when the container is started. Default is `False`.
* `AUTO_UPDATE_TRANSLATIONS` If enabled translatiosn will be updated when the container starts. Default is `False`.
* `AUTO_UPDATE_MODULES_LIST` If enabled, the modules list will be updated when the container starts. Default is `False`.
Both options require `ODOO_DATABASE` and `ODOO_ADDONS_PATH`.
+18
View File
@@ -0,0 +1,18 @@
#!/bin/bash
if [ -n "$ODOO_DATABASE" ]; then
echo "Check if database $ODOO_DATABASE is initialized."
DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'")
echo "Database initialization check result: $DATABASE_INITIALIZED"
if [ "$DATABASE_INITIALIZED" = "1" ]; then
echo "Database $ODOO_DATABASE is initialized."
exit 0
else
echo "Database $ODOO_DATABASE is not initialized."
exit 1
fi
else
echo "ODOO_DATABASE environment variable not set."
exit 1
fi
+14 -26
View File
@@ -2,16 +2,15 @@
if [ -n "$ODOO_DATABASE" ]; then
echo "Starting database initialization for $ODOO_DATABASE"
echo "Starting database initialization for $ODOO_DATABASE."
echo "Database connection: $PGUSER@$PGHOST:$PGPORT"
# Wait for database to be ready
echo "Waiting for database connection..."
until psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/postgres" -c '\q' 2>/dev/null; do
echo "Database not ready, waiting 2 seconds..."
sleep 2
done
echo "Database connection established"
echo "Database connection established."
echo "Check if database $ODOO_DATABASE exists..."
DATABASE_EXISTS=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/postgres" -tAc "SELECT COUNT(*) FROM pg_database WHERE datname = '$ODOO_DATABASE'")
@@ -19,18 +18,14 @@ if [ -n "$ODOO_DATABASE" ]; then
# If it does not exist, create it
if [ "$DATABASE_EXISTS" = "0" ]; then
echo "Create database $ODOO_DATABASE."
echo "Create database $ODOO_DATABASE..."
(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/postgres" -tAc "CREATE DATABASE \"$ODOO_DATABASE\";") || true
echo "Database creation completed"
echo "Database creation completed."
else
echo "Database $ODOO_DATABASE already exists"
echo "Database $ODOO_DATABASE already exists."
fi
echo "Check if database $ODOO_DATABASE is initialized"
DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'")
echo "Database initialization check result: $DATABASE_INITIALIZED"
if [ "$DATABASE_INITIALIZED" = "0" ]; then
if ! check-database-initialized; then
echo "Database not initialized, starting initialization process"
ODOO_INIT_DEMO_DATA=${ODOO_INIT_DEMO_DATA:=False}
ODOO_INIT_LOGIN=${ODOO_INIT_LOGIN:="admin"}
@@ -46,7 +41,7 @@ if [ -n "$ODOO_DATABASE" ]; then
echo "Initialize database $ODOO_DATABASE with modules: $ODOO_INIT_ADDONS."
(exec odoo "${DB_ARGS[@]}" --database "$ODOO_DATABASE" --init "$ODOO_INIT_ADDONS" --config "$ODOO_RC" --stop-after-init --no-http --load-language "$ODOO_INIT_LANG" $ODOO_INIT_PARAM) || true
echo "Odoo initialization command completed"
echo "Odoo initialization command completed."
if [ "$ODOO_INIT_LOGIN" != "admin" ] || [ "$ODOO_INIT_PASSWORD" != "admin" ]; then
echo "Updating admin user credentials to login: $ODOO_INIT_LOGIN"
@@ -57,21 +52,14 @@ admin_user.write({
'password': '$ODOO_INIT_PASSWORD'
})
env.cr.commit()
print('Admin credentials updated successfully')
print('Admin credentials updated successfully.')
EOF
) || true
echo "Admin credentials update completed"
echo "Admin credentials update completed."
fi
else
echo "Database $ODOO_DATABASE is already initialized (DATABASE_INITIALIZED=$DATABASE_INITIALIZED)"
fi
# Recheck database initialization status
echo "Rechecking database initialization status..."
DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'")
echo "Final database initialization status: $DATABASE_INITIALIZED"
if [ "$DATABASE_INITIALIZED" = "1" ]; then
if check-database-initialized; then
echo "Setting up mail server configuration..."
export ODOO_MAIL_SMTP_PORT=${ODOO_MAIL_SMTP_PORT:="587"}
export ODOO_MAIL_SMTP_ENCRYPTION=${ODOO_MAIL_SMTP_ENCRYPTION:="starttls"}
@@ -79,14 +67,14 @@ EOF
export ODOO_MAIL_IMAP_PORT=${ODOO_MAIL_IMAP_PORT:="993"}
export ODOO_MAIL_IMAP_SSL=${ODOO_MAIL_IMAP_SSL:="True"}
echo "Setup mail server configuration for database $ODOO_DATABASE"
echo "Setup mail server configuration for database $ODOO_DATABASE."
(odoo shell "${DB_ARGS[@]}" --database "$ODOO_DATABASE" --config "$ODOO_RC" --stop-after-init --no-http < /usr/local/bin/setup-mail) || true
echo "Mail server configuration completed"
echo "Mail server configuration completed."
else
echo "WARNING: Database initialization may have failed. DATABASE_INITIALIZED=$DATABASE_INITIALIZED"
echo "WARNING: Database initialization may have failed."
fi
echo "Database initialization process completed for $ODOO_DATABASE"
else
echo "ODOO_DATABASE environment variable not set, skipping database initialization"
echo "ODOO_DATABASE environment variable not set, skipping database initialization."
fi
+1 -4
View File
@@ -1,10 +1,7 @@
#!/bin/bash
if [ -n "$ODOO_DATABASE" ]; then
echo "Check if database $ODOO_DATABASE is initialized"
DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'")
if [ "$DATABASE_INITIALIZED" = "1" ]; then
if check-database-initialized; then
ODOO_INIT_LANG="${ODOO_INIT_LANG:="en_US"}"
echo "Initialize module $1 on database $ODOO_DATABASE."
+1 -4
View File
@@ -1,10 +1,7 @@
#!/bin/bash
if [ -n "$ODOO_DATABASE" ]; then
echo "Check if database $ODOO_DATABASE is initialized"
DATABASE_INITIALIZED=$(exec psql "postgres://$PGUSER:$PGPASSWORD@$PGHOST:$PGPORT/$ODOO_DATABASE" -tAc "SELECT COUNT(*) FROM information_schema.tables WHERE table_name = 'ir_module_module'")
if [ "$DATABASE_INITIALIZED" = "1" ]; then
if check-database-initialized; then
ODOO_INIT_LANG="${ODOO_INIT_LANG:="en_US"}"
echo "Update module $1 on database $ODOO_DATABASE."
+19
View File
@@ -0,0 +1,19 @@
#!/bin/bash
if [ -n "$ODOO_DATABASE" ]; then
if check-database-initialized; then
echo "Update modules list on database $ODOO_DATABASE."
# Execute Odoo shell command to call base.module.update:update_module()
(exec odoo shell "${DB_ARGS[@]}" --database "$ODOO_DATABASE" --config "$ODOO_RC" --stop-after-init --no-http << EOF
updater = env['base.module.update']
updater.update_module()
env.cr.commit()
print('Module list updated successfully.')
EOF
) || true
else
echo "Database $ODOO_DATABASE is not initialized, skipping modules list update."
fi
else
echo "ODOO_DATABASE environment variable not set, skipping modules list update."
fi
+4 -2
View File
@@ -3,12 +3,14 @@
source set-addons-path
if [ -n "$ODOO_DATABASE" ]; then
echo "Updating translations for all active languages and installed modules."
(exec odoo shell --database "$ODOO_DATABASE" --config "$ODOO_RC" << EOF
if check-database-initialized; then
echo "Updating translations for all active languages and installed modules."
(exec odoo shell --database "$ODOO_DATABASE" --config "$ODOO_RC" << EOF
for lang in env['res.lang'].search([]):
env['ir.module.module'].search([('state', '=', 'installed')])._update_translations(lang.code, overwrite=True)
env.cr.commit()
print('Translations updated successfully')
EOF
) || true
fi
fi
-1
View File
@@ -1,6 +1,5 @@
#!/bin/bash
MAX_ATTEMPTS=30
SLEEP_SECONDS=5
ATTEMPTS=0
+5
View File
@@ -53,6 +53,11 @@ if [ "$AUTO_UPDATE_MODULES" = "True" ]; then
update-modules
fi
AUTO_UPDATE_MODULES_LIST="${AUTO_UPDATE_MODULES_LIST:=False}"
if [ "$AUTO_UPDATE_MODULES_LIST" = "True" ]; then
update-modules-list
fi
AUTO_UPDATE_TRANSLATIONS="${AUTO_UPDATE_TRANSLATIONS:=False}"
if [ "$AUTO_UPDATE_TRANSLATIONS" = "True" ]; then
update-translations
+5 -2
View File
@@ -15,10 +15,13 @@ watchdog # python3-watchdog
rlPyCairo # python3-renderpm
lxml # python3-lxml
# Built-in
# Performance
memray
# OCA Tools
manifestoo
click-odoo-contrib
memray
git-aggregator
# Upgrade
git+https://github.com/OCA/openupgradelib.git@master
+1 -1
View File
@@ -32,5 +32,5 @@ manifestoo
oca-port
odoo-module-migrator
click-odoo-contrib
git+https://github.com/acsone/git-aggregator@master
git-aggregator
git+https://github.com/OCA/maintainer-tools
+2 -1
View File
@@ -625,7 +625,7 @@ function build() {
# Set container tag and platform based on Dockerfile
PLATFORM="linux/amd64"
if [ "$1" = "images/odoo" ]; then
PLATFORM="linux/amd64,linux/arm64"
# PLATFORM="linux/amd64,linux/arm64"
MANIFEST_FILE="images/odoo/Dockerfile"
CONTAINER_TAG="odoo:$ODOO_REVISION"
LATEST_TAG="odoo:$ODOO_VERSION"
@@ -1324,6 +1324,7 @@ function test-project() {
export MODULE_AUTO_INSTALL_DISABLED=odoo_test_xmlrunner
export AUTO_UPDATE_MODULES=True
export AUTO_UPDATE_TRANSLATIONS=True
export AUTO_UPDATE_MODULES_LIST=True
export MAIL_DEFAULT_FROM="test"
export BROWSER_OPEN=false
export TEST_ADDONS_DIR=/mnt/oca/partner-contact