ir_websocket.py 1.3 KB

1234567891011121314151617181920212223242526272829
  1. # -*- coding: utf-8 -*-
  2. from odoo import models, registry
  3. from odoo.api import Environment
  4. from odoo.fields import Datetime
  5. from odoo.http import request
  6. from odoo.addons.bus.websocket import wsrequest
  7. class IrWebsocket(models.AbstractModel):
  8. _inherit = 'ir.websocket'
  9. def _update_bus_presence(self, inactivity_period, im_status_ids_by_model):
  10. super()._update_bus_presence(inactivity_period, im_status_ids_by_model)
  11. # This method can either be called due to an http or a
  12. # websocket request. The request itself is necessary to
  13. # retrieve the current guest. Let's retrieve the proper
  14. # request.
  15. req = request or wsrequest
  16. if req.env.user._is_internal():
  17. ip_address = req.httprequest.remote_addr
  18. users_log = req.env['res.users.log'].search_count([
  19. ('create_uid', '=', req.env.user.id),
  20. ('ip', '=', ip_address),
  21. ('create_date', '>=', Datetime.to_string(Datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)))])
  22. if not users_log:
  23. with registry(req.env.cr.dbname).cursor() as cr:
  24. env = Environment(cr, req.env.user.id, {})
  25. env['res.users.log'].create({'ip': ip_address})