diff --git a/test-requirements.txt b/test-requirements.txt new file mode 100644 index 00000000..da9f588b --- /dev/null +++ b/test-requirements.txt @@ -0,0 +1 @@ +odoo-addon-server_environment @ git+https://github.com/OCA/server-env.git@refs/pull/288/head#subdirectory=server_environment diff --git a/webservice_server_env/__init__.py b/webservice_server_env/__init__.py index 071962a3..1a9a001c 100644 --- a/webservice_server_env/__init__.py +++ b/webservice_server_env/__init__.py @@ -1,2 +1,2 @@ from . import models -from .hooks import uninstall_hook +from .hooks import post_init_hook, uninstall_hook diff --git a/webservice_server_env/__manifest__.py b/webservice_server_env/__manifest__.py index ae315cb6..db9a1c10 100644 --- a/webservice_server_env/__manifest__.py +++ b/webservice_server_env/__manifest__.py @@ -14,6 +14,7 @@ "author": "Creu Blanca, Camptocamp, Odoo Community Association (OCA)", "website": "https://github.com/OCA/web-api", "depends": ["web", "webservice", "server_environment"], + "post_init_hook": "post_init_hook", "uninstall_hook": "uninstall_hook", "auto_install": True, } diff --git a/webservice_server_env/hooks.py b/webservice_server_env/hooks.py index 4eeb39d5..b860e489 100644 --- a/webservice_server_env/hooks.py +++ b/webservice_server_env/hooks.py @@ -3,32 +3,37 @@ from odoo.addons.server_environment.uninstall import restore_env_managed_columns +ENV_MANAGED_FIELDS = [ + "protocol", + "url", + "auth_type", + "username", + "password", + "api_key", + "api_key_header", + "content_type", + "oauth2_flow", + "oauth2_scope", + "oauth2_clientid", + "oauth2_client_secret", + "oauth2_authorization_url", + "oauth2_token_url", + "oauth2_audience", + "oauth2_token_method", + "oauth2_client_auth_method", + "oauth2_client_auth_header", + "oauth2_client_auth_value", +] -def uninstall_hook(env): - """Restore database columns dropped by server.env.mixin. - When the module is uninstalled, the columns managed by the server - environment mixin must be restored and repopulated with current values, - so the database remains usable. - """ +def post_init_hook(env): + env["webservice.backend"]._preserve_not_env_managed_data(ENV_MANAGED_FIELDS) + + +def uninstall_hook(env): + """Restore database columns dropped by server.env.mixin.""" restore_env_managed_columns( env, "webservice.backend", - [ - "protocol", - "url", - "auth_type", - "username", - "password", - "api_key", - "api_key_header", - "content_type", - "oauth2_flow", - "oauth2_scope", - "oauth2_clientid", - "oauth2_client_secret", - "oauth2_authorization_url", - "oauth2_token_url", - "oauth2_audience", - ], + ENV_MANAGED_FIELDS, )