前言
odoo聊天工具的启用需要启用nginx反向代理,具体配置见另一篇博文odoo中nginx反向代理配置
一、问题描述
odoo开两个窗口,对话消息发送出去后不能在当前界面显示,对方也不能及时收不到消息,都刷新页面后可以显示消息,翻阅无数网络回答,都没有解决。
网上普遍说是nginx的反向代理配置问题,反复设置也没有效果。
二、问题查找
最后还是通过反复测试看源代码,最后在addons/bus/models/bus.py的poll方法中发现了端倪,发送消息后会调用poll方法
方法见下:
@api.model
def poll(self, channels, last=0, options=None):
if options is None:
options = {}
# first poll return the notification in the 'buffer'
if last == 0:
timeout_ago = datetime.datetime.utcnow()-datetime.timedelta(seconds=TIMEOUT)
domain = [('create_date', '>', timeout_ago.strftime(DEFAULT_SERVER_DATETIME_FORMAT))]
else: # else returns the unread notifications
domain = [('id', '>', last)]
channels = [json_dump(c) for c in channels]
domain.append(('channel', 'in', channels))
notifications = self.sudo().search_read(domain)
# list of notification to return
result = []
for notif in notifications:
result.append({
'id': notif['id'],
'channel': json.loads(notif['channel']),
'message': json.loads(notif['message']),
})
return result
通过前端页面网址调用结果查看,返回值为空
{"jsonrpc": "2.0", "id": 745256989, "result": []}
通过输出domain,根据条件到数据库查询,竟然没有数据
select * from bus_bus where create_date > '2021-01-04 13:05:08' order by id DESC
查看数据库记录,如下图
再来仔细看下第一条数据
神奇的事情,message内的创建时间"date"的时间和字段create_date的时间相差一分钟以上了,最终导致查询不到数据,所以界面没有显示聊天内容
三、问题分析
导致出现时间不一致的问题原因是因为我的odoo的代码运行环境和postgresql数据库不在同一个服务器上,而且服务器没有做时间同步,所以导致两台服务器时间不一致,出现的此问题。
四、问题处理
处理时间同步,访问见另一博主文章
centos服务器时间同步