summaryrefslogtreecommitdiff
path: root/addons/bus/models/res_users.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/bus/models/res_users.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/bus/models/res_users.py')
-rw-r--r--addons/bus/models/res_users.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/addons/bus/models/res_users.py b/addons/bus/models/res_users.py
new file mode 100644
index 00000000..8e40c1b1
--- /dev/null
+++ b/addons/bus/models/res_users.py
@@ -0,0 +1,28 @@
+# -*- coding: utf-8 -*-
+
+from odoo import api, fields, models
+from odoo.addons.bus.models.bus_presence import AWAY_TIMER
+from odoo.addons.bus.models.bus_presence import DISCONNECTION_TIMER
+
+
+class ResUsers(models.Model):
+
+ _inherit = "res.users"
+
+ im_status = fields.Char('IM Status', compute='_compute_im_status')
+
+ def _compute_im_status(self):
+ """ Compute the im_status of the users """
+ self.env.cr.execute("""
+ SELECT
+ user_id as id,
+ CASE WHEN age(now() AT TIME ZONE 'UTC', last_poll) > interval %s THEN 'offline'
+ WHEN age(now() AT TIME ZONE 'UTC', last_presence) > interval %s THEN 'away'
+ ELSE 'online'
+ END as status
+ FROM bus_presence
+ WHERE user_id IN %s
+ """, ("%s seconds" % DISCONNECTION_TIMER, "%s seconds" % AWAY_TIMER, tuple(self.ids)))
+ res = dict(((status['id'], status['status']) for status in self.env.cr.dictfetchall()))
+ for user in self:
+ user.im_status = res.get(user.id, 'offline')