Files
odoo-ai/addons/activeblue_ai/__init__.py
Carlos Garcia 01f7037a38 fix(addon): create AI bot as internal user; use post_migrate_hook
- Bot needs to be a res.users to appear in Discuss DM search
- post_migrate_hook runs on both install and -u update
- Idempotent: skips creation if user already exists

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-24 22:20:09 -04:00

26 lines
797 B
Python

from . import models, controllers
import logging
_logger = logging.getLogger(__name__)
def _ensure_ai_bot_user(env):
"""Create the ActiveBlue AI internal user so it appears in Discuss DM search."""
if env['res.users'].search([('login', '=', 'activeblue_ai_bot')]):
return
user = env['res.users'].create({
'name': 'ActiveBlue AI',
'login': 'activeblue_ai_bot',
'groups_id': [(6, 0, [env.ref('base.group_user').id])],
'share': False,
'active': True,
})
env['ir.model.data'].create({
'module': 'activeblue_ai',
'name': 'partner_activeblue_ai',
'model': 'res.partner',
'res_id': user.partner_id.id,
'noupdate': True,
})
_logger.info('Created ActiveBlue AI bot user id=%d', user.id)