コード例 #1
0
ファイル: hr_clock.py プロジェクト: newmooncn/dm
 def refresh_clock_info(self, cr, uid, ids, context=None):  
     clock = clock_util.clock_obj()
     for clock_data in self.browse(cr, uid, ids, context=context):
         #connect clock
         clock_util.clock_connect(clock, clock_data.ip,clock_data.port)
         #download data
         clock_info = clock_util.clock_status(clock)
         #disconnect clock
         clock_util.clock_disconnect(clock)
         #update data
         self.write(cr, uid, clock_data.id, {'clock_info':clock_info},context=context)
         
     return True
コード例 #2
0
ファイル: hr_clock.py プロジェクト: newmooncn/dm
 def download_log(self, cr, uid, ids = False, context=False, emp_ids=False):
     if not context:
         context = {}
     if not ids:
         ids = self.search(cr, uid, [], context=context)
     emp_codes = []
     #get the emps by ids
     if emp_ids:
         emps = self.pool.get('hr.employee').read(cr, uid, emp_ids, ['emp_code'], context=context)
         emp_codes = [emp['emp_code'] for emp in emps]
         if not emp_codes:
             return False
         
     clock = clock_util.clock_obj()
     run_log = ''
     for clock_data in self.browse(cr, uid, ids, context=context):
         try:     
             #connect clock
             clock_util.clock_connect(clock, clock_data.ip,clock_data.port)
             #download data
             log_cnt, attend_ids = self._clock_download_log(cr, uid, clock_data.id, clock, emp_codes = emp_codes, context=context)
             '''
             move the calc_action calling to hr_attendance.create() method, johnw, 03/21/2015                
             #do the attendance action calculation
             if attend_ids:
                 self.pool.get('hr.attendance').calc_action(cr, uid, attend_ids, context=context)
             '''
             #if download the whole clock data, then log the message
             if not emp_codes:
                 #calling from cron or the clock GUI
                 msg = u'download clock[%s] log end at %s, log count:%s, new log count:%s'%(clock_data.name,datetime.now(), log_cnt, len(attend_ids))
                 run_log += msg + "\n"
                 self.message_post(cr, uid, clock_data.id, 
                                   type='comment', subtype='mail.mt_comment', 
                                   subject='download log data', 
                                   body=msg,
                                   content_subtype="plaintext",
                                   context=context)
             #disconnect clock
             clock_util.clock_disconnect(clock)
         except Exception,e:
             traceback.print_exc() 
             formatted_info = "".join(traceback.format_exception(*(sys.exc_info())))
             msg = 'download clock[%s] with exception at %s'%(clock_data.name, datetime.now()) + "\n" + formatted_info
             run_log += msg + "\n"
             self.message_post(cr, uid, clock_data.id, 
                               type='comment', subtype='mail.mt_comment', 
                               subject='download log data', 
                               body=msg,
                               content_subtype="plaintext",
                               context=context)
コード例 #3
0
ファイル: hr_clock.py プロジェクト: newmooncn/dm
 def set_clock_time(self, cr, uid, ids, clock_time = None, context=None):  
     clock = clock_util.clock_obj()
     for clock_data in self.browse(cr, uid, ids, context=context):
         #connect clock
         clock_util.clock_connect(clock, clock_data.ip,clock_data.port)
         #set clock time
         if not clock_time:
             clock_time = fields.datetime.context_timestamp(cr, uid, datetime.utcnow(), context)
         clock_util.clock_time_set(clock,clock_time)
         #refresh data including time
         clock_info = clock_util.clock_status(clock)
         #disconnect clock
         clock_util.clock_disconnect(clock)
         #update data
         self.write(cr, uid, clock_data.id, {'clock_info':clock_info},context=context)
     return True
コード例 #4
0
ファイル: hr_clock.py プロジェクト: 837278709/metro-openerp
    def refresh_clock_info(self, cr, uid, ids, context=None):
        clock = clock_util.clock_obj()
        for clock_data in self.browse(cr, uid, ids, context=context):
            #connect clock
            clock_util.clock_connect(clock, clock_data.ip, clock_data.port)
            #download data
            clock_info = clock_util.clock_status(clock)
            #disconnect clock
            clock_util.clock_disconnect(clock)
            #update data
            self.write(cr,
                       uid,
                       clock_data.id, {'clock_info': clock_info},
                       context=context)

        return True
コード例 #5
0
ファイル: hr_clock.py プロジェクト: 837278709/metro-openerp
 def set_clock_time(self, cr, uid, ids, clock_time=None, context=None):
     clock = clock_util.clock_obj()
     for clock_data in self.browse(cr, uid, ids, context=context):
         #connect clock
         clock_util.clock_connect(clock, clock_data.ip, clock_data.port)
         #set clock time
         if not clock_time:
             clock_time = fields.datetime.context_timestamp(
                 cr, uid, datetime.utcnow(), context)
         clock_util.clock_time_set(clock, clock_time)
         #refresh data including time
         clock_info = clock_util.clock_status(clock)
         #disconnect clock
         clock_util.clock_disconnect(clock)
         #update data
         self.write(cr,
                    uid,
                    clock_data.id, {'clock_info': clock_info},
                    context=context)
     return True
コード例 #6
0
ファイル: hr_clock.py プロジェクト: 837278709/metro-openerp
    def download_log(self, cr, uid, ids=False, context=False, emp_ids=False):
        if not context:
            context = {}
        if not ids:
            ids = self.search(cr, uid, [], context=context)
        emp_codes = []
        #get the emps by ids
        if emp_ids:
            emps = self.pool.get('hr.employee').read(cr,
                                                     uid,
                                                     emp_ids, ['emp_code'],
                                                     context=context)
            emp_codes = [emp['emp_code'] for emp in emps]
            if not emp_codes:
                return False

        clock = clock_util.clock_obj()
        run_log = ''
        for clock_data in self.browse(cr, uid, ids, context=context):
            try:
                #connect clock
                clock_util.clock_connect(clock, clock_data.ip, clock_data.port)
                #download data
                log_cnt, attend_ids = self._clock_download_log(
                    cr,
                    uid,
                    clock_data.id,
                    clock,
                    emp_codes=emp_codes,
                    context=context)
                #do the attendance action calculation
                if attend_ids:
                    self.pool.get('hr.attendance').calc_action(cr,
                                                               uid,
                                                               attend_ids,
                                                               context=context)
                #if download the whole clock data, then log the message
                if not emp_codes:
                    #calling from cron or the clock GUI
                    msg = u'download clock[%s] log end at %s, log count:%s, new log count:%s' % (
                        clock_data.name, datetime.now(), log_cnt,
                        len(attend_ids))
                    run_log += msg + "\n"
                    self.message_post(cr,
                                      uid,
                                      clock_data.id,
                                      type='comment',
                                      subtype='mail.mt_comment',
                                      subject='download log data',
                                      body=msg,
                                      content_subtype="plaintext",
                                      context=context)
                #disconnect clock
                clock_util.clock_disconnect(clock)
            except Exception, e:
                traceback.print_exc()
                formatted_info = "".join(
                    traceback.format_exception(*(sys.exc_info())))
                msg = 'download clock[%s] with exception at %s' % (
                    clock_data.name, datetime.now()) + "\n" + formatted_info
                run_log += msg + "\n"
                self.message_post(cr,
                                  uid,
                                  clock_data.id,
                                  type='comment',
                                  subtype='mail.mt_comment',
                                  subject='download log data',
                                  body=msg,
                                  content_subtype="plaintext",
                                  context=context)