This module provides a way to define an environment in the main Odoo configuration file and to read some configurations from files depending on the configured environment: you define the environment in the main configuration file, and the values for the various possible environments are stored in the server_environment_files companion module.
The server_environment_files module is optional, the values can be set using an environment variable with a fallback on default values in the database.
The configuration read from the files are visible under the Configuration menu. If you are not in the 'dev' environment you will not be able to see the values contained in the defined secret keys (by default : 'passw', 'key', 'secret' and 'token').
auto_awesome What this module does
AI-generated from the code · Odoo 19.0Lets administrators move sensitive or environment-specific settings (paths, credentials, server addresses) out of the Odoo database and into configuration files or environment variables, and view the active configuration from a dedicated screen.
This module gives Odoo a way to read certain settings from configuration files or environment variables instead of storing them in the database. Administrators can open the "Server Environment" screen under the Configuration menu to see the active Odoo options, the environment-based sections, and system information such as platform, Python and Odoo versions.
- Values are read from configuration files or from the SERVER_ENV_CONFIG and SERVER_ENV_CONFIG_SECRET environment variables, with the running environment chosen by the running_env setting or the RUNNING_ENV / ODOO_STAGE variables.
- When a setting is defined in the configuration, the matching field on the record becomes read-only and its value comes from the configuration; when it is not defined, the value can be edited and is stored in the database as a default.
- Secret values (keys containing pass, passw, key, secret or token) are shown as asterisks unless the running environment is dev.
- A technical name field can be used as a stable key for configuration sections, with automatic cleanup and a uniqueness check.
- Access to the configuration screen is limited to users in the "View Server Environment Configuration" group; only system administrators can change records.
The module touches models such as server.env.mixin, server.env.techname.mixin and server.config, and adds a menu item under the Configuration menu.
Depends on
Required by other modules
Menus it adds
Models and fields (3)
- server.config · new model
- server.env.mixin · new model
- server.env.techname.mixin · new modeltech_name
Text generated by AI (DeepSeek) from reading the Odoo 19.0 code on GitHub; it may contain mistakes, so check the code before deciding. View the code on GitHub
Availability by version
Reviewed: 2026-11-03Confirmation status: 8 confirmed, 1 with no information of 9 versions.
Sources · Odoo 14.0
Confirmed on 2026-11-03 in branch 14.0 of OCA/server-env.
terminal Installation and usage
OCA documentation · Odoo 19.0Installation
Source · Odoo 19.0By itself, this module does little. See for instance the mail_environment addon which depends on this one to allow configuring the incoming and outgoing mail servers depending on the environment.
You can store your configuration values in a companion module called server_environment_files. You can copy and customize the provided server_environment_files_sample module for this purpose. Alternatively, you can provide them in environment variables SERVER_ENV_CONFIG and SERVER_ENV_CONFIG_SECRET.
Configuration
Source · Odoo 19.0To configure this module, you need to edit the main configuration file of your instance, and add a directive called running_env. Commonly used values are 'dev', 'test', 'production':
[options] running_env=dev
Or set the RUNNING_ENV or ODOO_STAGE environment variable. If both all are set config file will take the precedence on environment and RUNNING_ENV over ODOO_STAGE.
ODOO_STAGE is used for odoo.sh platform where we can't set RUNNING_ENV, possible observed values are production, staging and dev
Values associated to keys containing 'passw' are only displayed in the 'dev' environment.
If you don't provide any value, test is used as a safe default.
You have several possibilities to set configuration values:
server_environment_files
You can edit the settings you need in the server_environment_files addon. The server_environment_files_sample can be used as an example:
- values common to all / most environments can be stored in the
default/directory using the .ini file syntax; - each environment you need to define is stored in its own directory and can override or extend default values;
- you can override or extend values in the main configuration file of your instance;
Environment variable
You can define configuration in the environment variable SERVER_ENV_CONFIG and/or SERVER_ENV_CONFIG_SECRET. The 2 variables are handled the exact same way, this is only a convenience for the deployment where you can isolate the secrets in a different, encrypted, file. They are multi-line environment variables in the same configparser format than the files. If you used options in server_environment_files, the options set in the environment variable override them.
The options in the environment variable are not dependent of running_env, the content of the variable must be set accordingly to the running environment.
Example of setup:
A public file, containing that will contain public variables:
# These variables are not odoo standard variables, # they are there to represent what your file could look like export WORKERS='8' export MAX_CRON_THREADS='1' export LOG_LEVEL=info export LOG_HANDLER=":INFO" export DB_MAXCONN=5
# server environment options export SERVER_ENV_CONFIG=" [storage_backend.my_sftp] sftp_server=10.10.10.10 sftp_login=foo sftp_port=22200 directory_path=Odoo "
A second file which is encrypted and contains secrets:
# This variable is not an odoo standard variable, # it is there to represent what your file could look like export DB_PASSWORD='xxxxxxxxx' # server environment options export SERVER_ENV_CONFIG_SECRET=" [storage_backend.my_sftp] sftp_password=xxxxxxxxx "
WARNING
> my_sftp must match the name of the record. If you want something more > reliable use server.env.techname.mixin and use tech_name field to > reference records. See "USAGE".
Default values
When using the server.env.mixin mixin, for each env-computed field, a companion field <field>_env_default is created. This field is not environment-dependent. It's a fallback value used when no key is set in configuration files / environment variable.
When the default field is used, the field is made editable on Odoo.
Note: empty environment keys always take precedence over default fields
Server environment integration
Read the documentation of the class models/server_env_mixin.py and [models/server_env_tech_name_mixin.py] (models/server_env_tech_name_mixin.py)
Usage
Source · Odoo 19.0You can include a mixin in your model and configure the env-computed fields by an override of _server_env_fields.
class StorageBackend(models.Model): _name = "storage.backend" _inherit = ["storage.backend", "server.env.mixin"]
@property def _server_env_fields(self): return {"directory_path": {}}
Read the documentation of the class and methods in models/server_env_mixin.py.
If you want to have a technical name to reference:
class StorageBackend(models.Model): _name = "storage.backend" _inherit = ["storage.backend", "server.env.techname.mixin"]
[...]
Restoring columns on uninstall
When server.env.mixin is bound to an existing model, the ORM drops the original stored columns for all env-managed fields. If the binding addon is later uninstalled, those columns must be recreated so the database remains usable.
Add an uninstall_hook to your addon and delegate to restore_env_managed_columns:
# your_addon/__init__.py from ./hooks import uninstall_hook # your_addon/hooks.py from odoo.addons.server_environment import uninstall
def uninstall_hook(env): uninstall.restore_env_managed_columns( env, "storage.backend", ["directory_path", "other_field"], )
# your_addon/__manifest__.py { "uninstall_hook": "uninstall_hook", }
The helper creates any missing columns (idempotent: safe to call multiple times) and repopulates them with each record's current effective value — whether that value came from an environment configuration file or from the stored default field (x_<field>_env_default).
The hook must run before the ORM extensions are removed, which is guaranteed by Odoo's uninstall sequence (hooks execute before Module.module_uninstall()).
Handling required fields
If a restored column is required (has a NOT NULL constraint) but has no effective value (missing from environment config and no default field set), the restoration will fail with a UserError.
Solution: pass a field_defaults dictionary with fallback values:
def uninstall_hook(env): restore_env_managed_columns( env, "ir.mail_server", ["smtp_host", "smtp_authentication"], field_defaults={ "smtp_authentication": "login", # fallback for required field }, )
The helper will use the fallback value if provided and the computed field value is empty. If no fallback is provided but a required field has no value, a UserError is raised with instructions on how to provide a field_defaults parameter.
Migrating when dropping server_environment dependency
When refactoring an existing addon that embeds a server.env.mixin binding, you may want to extract the binding into a separate glue addon and drop the server_environment dependency from the original. This keeps the base addon lightweight while preserving server-environment features for those who install the glue addon.
Pattern:
- Original addon (v1): depends on
server_environmentand binds the mixin directly in model code. - Refactored addon (v2): removes
server_environmentfrom dependencies, removes the mixin binding and the related ORM model inheritance. - New glue addon (optional, same version): depends on both
server_environmentand the original addon v2; re-adds the mixin binding in a separate module file.
Migration checklist:
- In the original addon's v2
__manifest__.py: - Remove
"server_environment"fromdepends. - Remove the model file(s) that contained the mixin binding.
- Update
dependsto add the new glue addon if the base addon still needs it (otherwise, make the glue addon optional for users who want env-binding). - In the original addon's v2 model code:
- Delete or simplify the model class that inherited from
server.env.mixin. - If the model was only there for the binding, remove it entirely.
- Restore the original field definitions (not as computed fields).
- Create a migration script (if needed) to restore columns during the addon upgrade, before the ORM model extensions are unloaded. Use a
@post_loadhook or a dedicated migration script: # migrations/18.0.1.0.0/post-restore-columns.py def migrate(cr, version): # Call the restoration logic while the v1 model is still active env = odoo.api.Environment(cr, odoo.SUPERUSER_ID, {}) # If any field is required and may have no value in the environment, # provide a fallback via field_defaults restore_env_managed_columns( env, "storage.backend", ["directory_path", "other_field"], field_defaults={ "directory_path": "/tmp", # fallback for required field }, ) - Create the glue addon with the model re-inheritance: # your_addon_env/__init__.py from . import models # your_addon_env/models/__init__.py from . import storage_backend # your_addon_env/models/storage_backend.py class StorageBackend(models.Model): _name = "storage.backend" _inherit = ["storage.backend", "server.env.mixin"] @property def _server_env_fields(self): return {"directory_path": {}} # your_addon_env/__manifest__.py { "name": "Storage Backend – Server Environment", "version": "18.0.1.0.0", "depends": ["server_environment", "storage_backend"], "installable": True, }
Key points:
- Column restoration must happen during the addon upgrade (step 3), not as an uninstall hook, because the original model binding is still active.
- The
restore_env_managed_columnshelper is idempotent and safe to call even if columns already exist. - Users who do not need server environment features simply do not install the glue addon—the base addon continues to work with plain database columns.
- Users who do need server environment can install both the base addon (v2+) and the glue addon (same version) to get the binding back.
Installation instructions, the distribution package, dependencies and configuration steps are not shown because they have not yet been verified in the module documentation for any version.
Data imported from GitHub: this sheet reflects the latest catalog review, not a live lookup. Always check the module documentation and staging before installing in production.