コード例 #1
0
    def default_get(self, cr, uid, fields, context=None):
        vals = super(hr_rpt_attend_emp_day, self).default_get(cr,
                                                              uid,
                                                              fields,
                                                              context=context)
        if 'date_from' in fields:
            #For the datetime value in defaults, need convert the local time to UTC, the web framework will convert them back to local time on GUI
            date_from = datetime.strptime(time.strftime('%Y-%m-01 00:00:00'),
                                          '%Y-%m-%d %H:%M:%S')
            date_from_utc = utils.utc_timestamp(cr, uid, date_from, context)
            vals.update({
                'date_from':
                date_from_utc.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
            })

        if 'date_to' in fields:
            date_to = datetime.now() + relativedelta.relativedelta(
                months=+1, day=1, days=-1)
            date_to = datetime.strptime(date_to.strftime('%Y-%m-%d 23:59:59'),
                                        '%Y-%m-%d %H:%M:%S')
            date_to_utc = utils.utc_timestamp(cr, uid, date_to, context)
            vals.update({
                'date_to':
                date_to_utc.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
            })

        return vals
コード例 #2
0
 def get_wt(self, cr, uid, emp_id, dt_para=None, context=None):
     '''
     @param dt_para: time with timezone, can be local or UTC tz, but the real time should be in local, that is the employee punching time 
     '''
     emp = self.browse(cr, uid, emp_id, context=context)
     if not emp.wt_grp_id or not emp.wt_grp_id.worktime_ids:
         return None
     if not dt_para:
         dt_para = datetime.now()
         #Assume above returns UTC time, convert it to time with local TZ
         dt_para = fields.datetime.context_timestamp(cr,
                                                     uid,
                                                     dt_para,
                                                     context=context)
     wt_found = None
     for wt in emp.wt_grp_id.worktime_ids:
         wt_from = datetime.strptime(wt.date_from + ' 00:00:00',
                                     DEFAULT_SERVER_DATETIME_FORMAT)
         wt_to = datetime.strptime(wt.date_to + ' 23:59:59',
                                   DEFAULT_SERVER_DATETIME_FORMAT)
         #above from/to shoule be treated as same as user's local time, so need convert them from local to UTC
         wt_from = utils.utc_timestamp(cr, uid, wt_from, context=context)
         wt_to = utils.utc_timestamp(cr, uid, wt_to, context=context)
         #the dt_para with local TZ can be compare with the from/to with UTC TZ
         if dt_para >= wt_from and dt_para <= wt_to:
             wt_found = wt.calendar_id
             break
     return wt_found
コード例 #3
0
 def _convert_save_dates(self, cr, uid, vals, context):
     #convert to the date like '2013-01-01' to UTC datetime to store
     if 'date_from' in vals and len(vals['date_from']) == 10:
         date_from = vals['date_from']
         date_from = utils.utc_timestamp(cr, uid, datetime.strptime(date_from + ' 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT),context=context)
         date_from = date_from.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
         vals['date_from'] = date_from
     if 'date_to' in vals and len(vals['date_to']) == 10:
         date_to = vals['date_to']
         date_to = utils.utc_timestamp(cr, uid, datetime.strptime(date_to + ' 23:59:59', DEFAULT_SERVER_DATETIME_FORMAT),context=context)
         date_to = date_to.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
         vals['date_to'] = date_to
コード例 #4
0
 def _convert_save_dates(self, cr, uid, vals, context):
     #convert to the date like '2013-01-01' to UTC datetime to store
     if 'date_from' in vals and len(vals['date_from']) == 10:
         date_from = vals['date_from']
         date_from = utils.utc_timestamp(cr, uid, datetime.strptime(date_from + ' 00:00:00', DEFAULT_SERVER_DATETIME_FORMAT),context=context)
         date_from = date_from.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
         vals['date_from'] = date_from
     if 'date_to' in vals and len(vals['date_to']) == 10:
         date_to = vals['date_to']
         date_to = utils.utc_timestamp(cr, uid, datetime.strptime(date_to + ' 23:59:59', DEFAULT_SERVER_DATETIME_FORMAT),context=context)
         date_to = date_to.strftime(DEFAULT_SERVER_DATETIME_FORMAT)
         vals['date_to'] = date_to
    def default_get(self, cr, uid, fields, context=None):
        vals = super(hr_rpt_attend_emp_day, self).default_get(cr, uid, fields, context=context)
        if "date_from" in fields:
            # For the datetime value in defaults, need convert the local time to UTC, the web framework will convert them back to local time on GUI
            date_from = datetime.strptime(time.strftime("%Y-%m-01 00:00:00"), "%Y-%m-%d %H:%M:%S")
            date_from_utc = utils.utc_timestamp(cr, uid, date_from, context)
            vals.update({"date_from": date_from_utc.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})

        if "date_to" in fields:
            date_to = datetime.strptime(time.strftime("%Y-%m-%d 23:59:59"), "%Y-%m-%d %H:%M:%S")
            date_to_utc = utils.utc_timestamp(cr, uid, date_to, context)
            vals.update({"date_to": date_to_utc.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})

        return vals
コード例 #6
0
 def default_get(self, cr, uid, fields, context=None):
     vals = super(hr_rpt_attend_emp_day, self).default_get(cr, uid, fields, context=context)
     if 'date_from' in fields:
         #For the datetime value in defaults, need convert the local time to UTC, the web framework will convert them back to local time on GUI
         date_from =datetime.strptime(time.strftime('%Y-%m-01 00:00:00'), '%Y-%m-%d %H:%M:%S')
         date_from_utc = utils.utc_timestamp(cr, uid, date_from, context)
         vals.update({'date_from':date_from_utc.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})
                      
     if 'date_to' in fields:
         date_to = datetime.now() + relativedelta.relativedelta(months=+1, day=1, days=-1)
         date_to = datetime.strptime(date_to.strftime('%Y-%m-%d 23:59:59'), '%Y-%m-%d %H:%M:%S')        
         date_to_utc = utils.utc_timestamp(cr, uid, date_to, context)        
         vals.update({'date_to':date_to_utc.strftime(DEFAULT_SERVER_DATETIME_FORMAT)})
                 
     return vals
コード例 #7
0
ファイル: hr_clock.py プロジェクト: Elbagoury/metro-openerp
 def _attend_create(self, cr, uid, md5_src, data, context=False):
     emp_obj = self.pool.get('hr.employee')
     attendence_obj = self.pool.get('hr.attendance')
     #use the md5 value to check do we need download the data to database
     md5=hashlib.md5(md5_src.encode('utf-8')).hexdigest()
     if not attendence_obj.search(cr, uid, [('clock_log_id','=',md5)],context=context):
         emp_code = emp_obj.search(cr, uid, [('emp_code','=',data['emp_code'])], context=context)
         if not emp_code:
             return False
         emp_id = emp_code[0]
         employee = emp_obj.browse(cr, uid, emp_id, context=context)
         #decide the sign in or out
         action = 'action'
         '''
         #move to download_log() to calculate all new attendance together, to improve the performance.
         '''
         #convert to UTC time
         data['time'] = utils.utc_timestamp(cr, uid, data['time'], context)            
         calendar_id = emp_obj.get_wt(cr, uid, emp_id, data['time'], context=context)
         vals = {'name':data['time'],
                 'employee_id': emp_id,
                 'action': action,  
                 'clock_log_id':md5, 
                 'notes':data['notes'],
                 'clock_id':data['clock_id'],
                 'calendar_id': calendar_id and calendar_id.id or None}
         return attendence_obj.create(cr, uid, vals, context=context)
     else:
         return 0
コード例 #8
0
 def get_wt(self, cr, uid, emp_id, dt_para=None, context=None):
     '''
     @param dt_para: time with timezone, can be local or UTC tz, but the real time should be in local, that is the employee punching time 
     '''
     emp = self.browse(cr, uid, emp_id, context=context)
     if not emp.wt_grp_id or not emp.wt_grp_id.worktime_ids:
         return None
     if not dt_para:
         dt_para = datetime.now()
         #Assume above returns UTC time, convert it to time with local TZ
         dt_para = fields.datetime.context_timestamp(cr, uid, dt_para, context=context) 
     wt_found = None
     for wt in emp.wt_grp_id.worktime_ids:            
         wt_from =  datetime.strptime(wt.date_from + ' 00:00:00',DEFAULT_SERVER_DATETIME_FORMAT)
         wt_to  = datetime.strptime(wt.date_to + ' 23:59:59', DEFAULT_SERVER_DATETIME_FORMAT)
         #above from/to shoule be treated as same as user's local time, so need convert them from local to UTC
         wt_from = utils.utc_timestamp(cr, uid, wt_from, context=context)
         wt_to = utils.utc_timestamp(cr, uid, wt_to, context=context)
         #the dt_para with local TZ can be compare with the from/to with UTC TZ 
         if dt_para >= wt_from and dt_para <= wt_to:
             wt_found = wt.calendar_id
             break
     return wt_found
コード例 #9
0
ファイル: hr_clock.py プロジェクト: 837278709/metro-openerp
 def _attend_create(self, cr, uid, md5_src, data, context=False):
     emp_obj = self.pool.get('hr.employee')
     attendence_obj = self.pool.get('hr.attendance')
     #use the md5 value to check do we need download the data to database
     md5 = hashlib.md5(md5_src.encode('utf-8')).hexdigest()
     if not attendence_obj.search(
             cr, uid, [('clock_log_id', '=', md5)], context=context):
         emp_code = emp_obj.search(cr,
                                   uid,
                                   [('emp_code', '=', data['emp_code'])],
                                   context=context)
         if not emp_code:
             return False
         emp_id = emp_code[0]
         employee = emp_obj.browse(cr, uid, emp_id, context=context)
         #decide the sign in or out
         action = 'action'
         '''
         #move to download_log() to calculate all new attendance together, to improve the performance.
         '''
         #convert to UTC time
         data['time'] = utils.utc_timestamp(cr, uid, data['time'], context)
         calendar_id = emp_obj.get_wt(cr,
                                      uid,
                                      emp_id,
                                      data['time'],
                                      context=context)
         vals = {
             'name': data['time'],
             'employee_id': emp_id,
             'action': action,
             'clock_log_id': md5,
             'notes': data['notes'],
             'clock_id': data['clock_id'],
             'calendar_id': calendar_id and calendar_id.id or None
         }
         return attendence_obj.create(cr, uid, vals, context=context)
     else:
         return 0