From 103f575f9286e7ad44e6a6159d2ca7bb1b9f8d45 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Date: Tue, 12 May 2026 22:42:35 -0400 Subject: [PATCH] =?UTF-8?q?fix(addon):=20bot=20presence=20=E2=80=94=20fix?= =?UTF-8?q?=20network=20isolation,=20computed=20field=20write,=20and=20tim?= =?UTF-8?q?er=20gap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- addons/activeblue_ai/data/ir_cron.xml | 4 +-- addons/activeblue_ai/models/ab_ai_bot.py | 33 +++++++++++++++++------- docker-compose.odoo.yml | 5 +++- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/addons/activeblue_ai/data/ir_cron.xml b/addons/activeblue_ai/data/ir_cron.xml index 4c2bf16..fd9ca7e 100644 --- a/addons/activeblue_ai/data/ir_cron.xml +++ b/addons/activeblue_ai/data/ir_cron.xml @@ -6,8 +6,8 @@ code model.cron_ping_all() - 1 - minutes + 20 + seconds True diff --git a/addons/activeblue_ai/models/ab_ai_bot.py b/addons/activeblue_ai/models/ab_ai_bot.py index 8719695..6302ed0 100644 --- a/addons/activeblue_ai/models/ab_ai_bot.py +++ b/addons/activeblue_ai/models/ab_ai_bot.py @@ -1,5 +1,6 @@ from odoo import models, fields, api, _ from odoo.exceptions import UserError +from datetime import timedelta import requests import logging @@ -132,13 +133,25 @@ class AbAiBot(models.Model): return if 'bus.presence' not in self.env: return - Presence = self.env['bus.presence'] - status = 'online' if online else 'offline' - now = fields.Datetime.now() - rec = Presence.sudo().search([('user_id', '=', bot_user.id)], limit=1) - vals = {'status': status, 'last_poll': now, 'last_presence': now} - if rec: - rec.write(vals) - else: - vals['user_id'] = bot_user.id - Presence.sudo().create(vals) + try: + Presence = self.env['bus.presence'] + now = fields.Datetime.now() + # bus.presence.status is a computed field — write only last_poll/last_presence. + # When online: set last_poll 90s ahead so the bot stays "online" across the + # full 60s cron cycle (Odoo DISCONNECTION_TIMER is 30s). + # When offline: set last_poll an hour in the past to force "offline" state. + if online: + poll_time = now + timedelta(seconds=90) + 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) diff --git a/docker-compose.odoo.yml b/docker-compose.odoo.yml index 32900a0..a0a5d13 100644 --- a/docker-compose.odoo.yml +++ b/docker-compose.odoo.yml @@ -13,7 +13,7 @@ services: volumes: - ./odoo-ai-data:/var/lib/odoo - ./odoo-ai-config:/etc/odoo - - ./odoo_module:/mnt/extra-addons + - ./addons:/mnt/extra-addons ports: [] restart: unless-stopped labels: @@ -25,6 +25,7 @@ services: networks: - traefik-public - odoo-ai-internal + - activeblue-net odoo-ai-db: image: postgres:15 @@ -48,6 +49,8 @@ networks: external: true odoo-ai-internal: driver: bridge + activeblue-net: + external: true volumes: odoo-ai-db-data: