fix(addon): create bot partner via post_init_hook instead of XML
XML record creation bypasses ORM defaults causing NOT NULL violation on autopost_bills (added by account module). Hook uses ORM create() which applies all field defaults correctly. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1 +1,23 @@
|
||||
from . import models, controllers
|
||||
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)
|
||||
|
||||
@@ -15,7 +15,6 @@ CRM, sales, project management, eLearning, expenses, and HR.
|
||||
'data': [
|
||||
'security/res_groups.xml',
|
||||
'security/ir.model.access.csv',
|
||||
'data/res_partner_bot.xml',
|
||||
'data/ir_cron.xml',
|
||||
'views/ab_ai_bot_views.xml',
|
||||
'views/ab_ai_directive_views.xml',
|
||||
@@ -35,4 +34,5 @@ CRM, sales, project management, eLearning, expenses, and HR.
|
||||
'installable': True,
|
||||
'application': True,
|
||||
'auto_install': False,
|
||||
'post_init_hook': '_create_ai_bot_partner',
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user