fix(addon): bot presence — fix network isolation, computed field write, and timer gap

- docker-compose.odoo.yml: add activeblue-net so Odoo can reach
  activeblue-agent by hostname; fix addons volume mount (was odoo_module)
- ab_ai_bot.py: bus.presence.status is computed — write only last_poll
  and last_presence; set last_poll 90s ahead when online so the bot
  stays green across the 60s cron cycle (DISCONNECTION_TIMER=30s)
- ir_cron.xml: reduce ping interval to 20s (uses Odoo 18 seconds type)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Carlos Garcia
2026-05-12 22:42:35 -04:00
parent f30751a696
commit 103f575f92
3 changed files with 29 additions and 13 deletions

View File

@@ -6,8 +6,8 @@
<field name="model_id" ref="model_ab_ai_bot"/> <field name="model_id" ref="model_ab_ai_bot"/>
<field name="state">code</field> <field name="state">code</field>
<field name="code">model.cron_ping_all()</field> <field name="code">model.cron_ping_all()</field>
<field name="interval_number">1</field> <field name="interval_number">20</field>
<field name="interval_type">minutes</field> <field name="interval_type">seconds</field>
<field name="active">True</field> <field name="active">True</field>
</record> </record>

View File

@@ -1,5 +1,6 @@
from odoo import models, fields, api, _ from odoo import models, fields, api, _
from odoo.exceptions import UserError from odoo.exceptions import UserError
from datetime import timedelta
import requests import requests
import logging import logging
@@ -132,13 +133,25 @@ class AbAiBot(models.Model):
return return
if 'bus.presence' not in self.env: if 'bus.presence' not in self.env:
return return
Presence = self.env['bus.presence'] try:
status = 'online' if online else 'offline' Presence = self.env['bus.presence']
now = fields.Datetime.now() now = fields.Datetime.now()
rec = Presence.sudo().search([('user_id', '=', bot_user.id)], limit=1) # bus.presence.status is a computed field — write only last_poll/last_presence.
vals = {'status': status, 'last_poll': now, 'last_presence': now} # When online: set last_poll 90s ahead so the bot stays "online" across the
if rec: # full 60s cron cycle (Odoo DISCONNECTION_TIMER is 30s).
rec.write(vals) # When offline: set last_poll an hour in the past to force "offline" state.
else: if online:
vals['user_id'] = bot_user.id poll_time = now + timedelta(seconds=90)
Presence.sudo().create(vals) presence_time = now
else:
poll_time = now - timedelta(hours=1)
presence_time = now - timedelta(hours=1)
vals = {'last_poll': poll_time, 'last_presence': presence_time}
rec = Presence.sudo().search([('user_id', '=', bot_user.id)], limit=1)
if rec:
rec.write(vals)
else:
vals['user_id'] = bot_user.id
Presence.sudo().create(vals)
except Exception as exc:
_logger.warning('Could not update bot user presence: %s', exc)

View File

@@ -13,7 +13,7 @@ services:
volumes: volumes:
- ./odoo-ai-data:/var/lib/odoo - ./odoo-ai-data:/var/lib/odoo
- ./odoo-ai-config:/etc/odoo - ./odoo-ai-config:/etc/odoo
- ./odoo_module:/mnt/extra-addons - ./addons:/mnt/extra-addons
ports: [] ports: []
restart: unless-stopped restart: unless-stopped
labels: labels:
@@ -25,6 +25,7 @@ services:
networks: networks:
- traefik-public - traefik-public
- odoo-ai-internal - odoo-ai-internal
- activeblue-net
odoo-ai-db: odoo-ai-db:
image: postgres:15 image: postgres:15
@@ -48,6 +49,8 @@ networks:
external: true external: true
odoo-ai-internal: odoo-ai-internal:
driver: bridge driver: bridge
activeblue-net:
external: true
volumes: volumes:
odoo-ai-db-data: odoo-ai-db-data: