Skip to content

Commit

Permalink
[IMP] Use server.env.techname.mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
florian-dacosta committed Sep 7, 2023
1 parent 13b3844 commit d8d8c33
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -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)})
19 changes: 7 additions & 12 deletions auth_api_key_server_env/models/auth_api_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit d8d8c33

Please sign in to comment.