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:
@@ -6,8 +6,8 @@
|
||||
<field name="model_id" ref="model_ab_ai_bot"/>
|
||||
<field name="state">code</field>
|
||||
<field name="code">model.cron_ping_all()</field>
|
||||
<field name="interval_number">1</field>
|
||||
<field name="interval_type">minutes</field>
|
||||
<field name="interval_number">20</field>
|
||||
<field name="interval_type">seconds</field>
|
||||
<field name="active">True</field>
|
||||
</record>
|
||||
|
||||
|
||||
@@ -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
|
||||
try:
|
||||
Presence = self.env['bus.presence']
|
||||
status = 'online' if online else 'offline'
|
||||
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)
|
||||
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)
|
||||
except Exception as exc:
|
||||
_logger.warning('Could not update bot user presence: %s', exc)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user