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
    • 293
    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

     def updates(self, user_presence=True):
      
            presence = self.search([('user_id', '=', self._uid)], limit=1)
            send_notification = True
            values = {
                'last_poll': time.strftime(DEFAULT_SERVER_DATETIME_FORMAT),
                'status': presence and presence.status or 'offline'
            }
            if not presence:  # create a new presence for the user
                values['status'] = 'online'
                values['user_id'] = self._uid
                self.create(values)
            else:  
                if user_presence:
                    values['last_presence'] = time.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
                    values['status'] = 'online'
                else:
                    threshold = datetime.datetime.now() - datetime.timedelta(seconds=AWAY_TIMER)
                    if datetime.datetime.strptime(presence.last_presence, DEFAULT_SERVER_DATETIME_FORMAT) < threshold:
                        values['status'] = 'away'
                send_notification = presence.status != values['status']
                # write only if the last_poll is passed TIMEOUT, or if the status has changed
                delta = datetime.datetime.utcnow() - datetime.datetime.strptime(presence.last_poll, DEFAULT_SERVER_DATETIME_FORMAT)
                if delta > datetime.timedelta(seconds=TIMEOUT) or send_notification:
                    # Hide transaction serialization errors, which can be ignored, the presence update is not essential
                    with tools.mute_logger('openerp.sql_db'):
                        presence.write(values)
            self.env.cr.commit() # TODO : check if still necessary
            if send_notification: 
                self.env['bus.bus'].sendone((self._cr.dbname, 'bus.presence'), {'id': self._uid, 'im_status': values['status']})
           
            if random.random() < 0.01:
                self.check_users_disconnection()
            return True
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: