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:
@@ -4,20 +4,22 @@ import logging
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def _create_ai_bot_partner(env):
|
||||
"""Create the ActiveBlue AI bot partner via ORM so all field defaults are applied."""
|
||||
XID = 'activeblue_ai.partner_activeblue_ai'
|
||||
if not env.ref(XID, raise_if_not_found=False):
|
||||
partner = env['res.partner'].create({
|
||||
'name': 'ActiveBlue AI',
|
||||
'active': True,
|
||||
'partner_share': False,
|
||||
})
|
||||
env['ir.model.data'].create({
|
||||
'module': 'activeblue_ai',
|
||||
'name': 'partner_activeblue_ai',
|
||||
'model': 'res.partner',
|
||||
'res_id': partner.id,
|
||||
'noupdate': True,
|
||||
})
|
||||
_logger.info('Created ActiveBlue AI bot partner id=%d', partner.id)
|
||||
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)
|
||||
|
||||
@@ -34,5 +34,6 @@ CRM, sales, project management, eLearning, expenses, and HR.
|
||||
'installable': True,
|
||||
'application': True,
|
||||
'auto_install': False,
|
||||
'post_init_hook': '_create_ai_bot_partner',
|
||||
'post_init_hook': '_ensure_ai_bot_user',
|
||||
'post_migrate_hook': '_ensure_ai_bot_user',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user