From d8d8c33cf905221c6ee1e8747f1ac903dffc0640 Mon Sep 17 00:00:00 2001 From: Florian da Costa Date: Thu, 7 Sep 2023 18:13:24 +0200 Subject: [PATCH] [IMP] Use server.env.techname.mixin --- .../migrations/16.0.1.0.0/post-migration.py | 8 ++++++++ .../models/auth_api_key.py | 19 +++++++------------ 2 files changed, 15 insertions(+), 12 deletions(-) create mode 100644 auth_api_key_server_env/migrations/16.0.1.0.0/post-migration.py diff --git a/auth_api_key_server_env/migrations/16.0.1.0.0/post-migration.py b/auth_api_key_server_env/migrations/16.0.1.0.0/post-migration.py new file mode 100644 index 0000000000..760b780ca3 --- /dev/null +++ b/auth_api_key_server_env/migrations/16.0.1.0.0/post-migration.py @@ -0,0 +1,8 @@ +from odoo import SUPERUSER_ID, api + + +def migrate(cr, version): + env = api.Environment(cr, SUPERUSER_ID, {}) + keys = env['auth.api.key'].search([("tech_name", '=', False), ("name", "!=", False)]) + for key in keys: + key.write({"tech_name": key._normalize_tech_name(key.name)}) diff --git a/auth_api_key_server_env/models/auth_api_key.py b/auth_api_key_server_env/models/auth_api_key.py index baabfde16e..516c66cdbc 100644 --- a/auth_api_key_server_env/models/auth_api_key.py +++ b/auth_api_key_server_env/models/auth_api_key.py @@ -4,26 +4,21 @@ # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). -from odoo import models +from odoo import api, models class AuthApiKey(models.Model): _name = "auth.api.key" - _inherit = ["auth.api.key", "server.env.mixin"] + _inherit = ["auth.api.key", "server.env.mixin", "server.env.techname.mixin"] - def _server_env_section_name(self): - """Name of the section in the configuration files - - We override the default implementation to keep the compatibility - with the previous implementation of auth_api_key. The section name - into the configuration file must be formatted as - - 'api_key_{name}' + @api.model + def _server_env_global_section_name(self): + """Name of the global section in the configuration files + Can be customized in your model """ - self.ensure_one() - return "api_key_{}".format(self.name) + return "api_key" @property def _server_env_fields(self):