Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to given presence of the current user in OpenERP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 341
    Comment on it

    In OpenERP first we create users and then validate to the trigger. Users register then status will not be sent if not necessary. In usres form type is user_presence.

    Use this function show in given below

    1. def updates(self, user_presence=True):
    2. presence = self.search([('user_id', '=', self._uid)], limit=1)
    3. send_notification = True
    4. values = {
    5. 'last_poll': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
    6. 'status': presence and presence.status or 'offline'
    7. }
    8. if not presence: # create a new presence for the user
    9. values['status'] = 'online'
    10. values['user_id'] = self._uid
    11. self.create(values)
    12. else:
    13. if user_presence:
    14. values['last_presence'] = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
    15. values['status'] = 'online'
    16. else:
    17. threshold = datetime.datetime.now() - datetime.timedelta(seconds=AWAY_TIMER)
    18. if datetime.datetime.strptime(presence.last_presence, DEFAULT_SERVER_DATETIME_FORMAT) < threshold:
    19. values['status'] = 'away'
    20. send_notification = presence.status != values['status']
    21. # write only if the last_poll is passed TIMEOUT, or if the status has changed
    22. delta = datetime.datetime.utcnow() - datetime.datetime.strptime(presence.last_poll, DEFAULT_SERVER_DATETIME_FORMAT)
    23. if delta > datetime.timedelta(seconds=TIMEOUT) or send_notification:
    24. # Hide transaction serialization errors, which can be ignored, the presence update is not essential
    25. with tools.mute_logger('openerp.sql_db'):
    26. presence.write(values)
    27. self.env.cr.commit() # TODO : check if still necessary
    28. if send_notification:
    29. self.env['bus.bus'].sendone((self._cr.dbname, 'bus.presence'), {'id': self._uid, 'im_status': values['status']})
    30. if random.random() < 0.01:
    31. self.check_users_disconnection()
    32. return True
    33.  

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Reset Password
Fill out the form below and reset your password: