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>
This commit is contained in:
Carlos Garcia
2026-04-24 22:20:09 -04:00
parent d5381220fb
commit 01f7037a38
2 changed files with 21 additions and 18 deletions

View File

@@ -4,20 +4,22 @@ import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
def _create_ai_bot_partner(env): def _ensure_ai_bot_user(env):
"""Create the ActiveBlue AI bot partner via ORM so all field defaults are applied.""" """Create the ActiveBlue AI internal user so it appears in Discuss DM search."""
XID = 'activeblue_ai.partner_activeblue_ai' if env['res.users'].search([('login', '=', 'activeblue_ai_bot')]):
if not env.ref(XID, raise_if_not_found=False): return
partner = env['res.partner'].create({ user = env['res.users'].create({
'name': 'ActiveBlue AI', 'name': 'ActiveBlue AI',
'active': True, 'login': 'activeblue_ai_bot',
'partner_share': False, 'groups_id': [(6, 0, [env.ref('base.group_user').id])],
}) 'share': False,
env['ir.model.data'].create({ 'active': True,
'module': 'activeblue_ai', })
'name': 'partner_activeblue_ai', env['ir.model.data'].create({
'model': 'res.partner', 'module': 'activeblue_ai',
'res_id': partner.id, 'name': 'partner_activeblue_ai',
'noupdate': True, 'model': 'res.partner',
}) 'res_id': user.partner_id.id,
_logger.info('Created ActiveBlue AI bot partner id=%d', partner.id) 'noupdate': True,
})
_logger.info('Created ActiveBlue AI bot user id=%d', user.id)

View File

@@ -34,5 +34,6 @@ CRM, sales, project management, eLearning, expenses, and HR.
'installable': True, 'installable': True,
'application': True, 'application': True,
'auto_install': False, 'auto_install': False,
'post_init_hook': '_create_ai_bot_partner', 'post_init_hook': '_ensure_ai_bot_user',
'post_migrate_hook': '_ensure_ai_bot_user',
} }