class AttException(CachingModel): ''' 请假明细表模型(异常记录表)【统计结果】 ''' UserID = EmpForeignKey(verbose_name=_(u'人员'),db_column='UserId', blank=False, null=False) StartTime = models.DateTimeField(_(u'开始时间'), db_column='StartTime') EndTime = models.DateTimeField(_(u'结束时间'), db_column='EndTime') ExceptionID=models.IntegerField(_(u'请假类型'),null=True,blank=True,default=0) AuditExcID=models.IntegerField(_(u'审核状态'),null=True,blank=True,default=0) OldAuditExcID=models.IntegerField(_(u'前次审核状态'),null=True,blank=True,default=0) OverlapTime=models.IntegerField(_(u'排班时长'),db_column='OverlapTime',null=True,blank=True,default=0) TimeLong=models.IntegerField(_(u'总时长(分钟)'), db_column='TimeLong',null=True,blank=True,default=0) InScopeTime=models.IntegerField(_(u'有效时长(分钟)'), db_column='InScopeTime',null=True,blank=True,default=0) AttDate=models.DateTimeField(_(u'日期'),db_column='AttDate',null=True,blank=True) OverlapWorkDayTail=models.IntegerField( db_column='OverlapWorkDayTail') OverlapWorkDay=models.FloatField(_(u'排班工作日'),db_column='OverlapWorkDay',null=True,default=1,blank=True) schindex=models.IntegerField(db_column='schindex',null=True,blank=True,default=0) Minsworkday=models.IntegerField(db_column='Minsworkday',null=True,blank=True,default=0) Minsworkday1=models.IntegerField(db_column='Minsworkday1',null=True,blank=True,default=0) schid=models.IntegerField(db_column='schid',null=True,blank=True,default=0) class Admin(CachingModel.Admin): default_give_perms=["contenttypes.can_AttCalculate",] visible=False list_display=('UserID_id','UserID.PIN','UserID.EName','UserID.DeptID','StartTime','EndTime','ExceptionID|AttExceptDesc','InScopeTime') class Meta: app_label='att' db_table='attexception' unique_together = (("UserID","AttDate", "StartTime"),)
class attRecAbnormite(models.Model): ''' 统计结果详情 ''' UserID = EmpForeignKey(verbose_name=_(u'人员'), db_column='userid') checktime = models.DateTimeField(_(u'考勤时间'), db_column='checktime') CheckType = models.CharField(_(u'考勤状态'), db_column='CheckType', max_length=5, choices=ATTSTATES) NewType = models.CharField(_(u'更正状态'), db_column='NewType', max_length=2, null=True, blank=True, choices=ATTSTATES) AbNormiteID = models.IntegerField(db_column='AbNormiteID', null=True, blank=True) SchID = models.IntegerField(_(u'时段'), db_column='SchID', null=True, blank=True) OP = models.IntegerField(_(u'操作'), db_column='OP', null=True, blank=True) AttDate = models.DateTimeField(_(u'日期'), db_column='AttDate', null=True, blank=True) def __unicode__(self): return unicode(u"%s" % (self.UserID)) class Admin: default_give_perms = ["contenttypes.can_AttCalculate"] sort_fields = ["UserID.PIN"] app_menu = "att_set" api_fields = ('UserID.PIN', 'UserID.EName', 'checktime', 'CheckType', 'NewType') list_display = ('UserID_id', 'UserID.PIN', 'UserID.EName', 'checktime', 'CheckType', 'NewType') visible = False class Meta: app_label = 'att' verbose_name = _(u"统计结果详情") db_table = 'attrecabnormite' unique_together = (("UserID", "AttDate", "checktime"), )
class att_record(CachingModel): ID = models.AutoField(primary_key=True, null=False, editable=False) EmpID = EmpForeignKey(verbose_name=_(u'人员'), null=False) SchID = models.ForeignKey("SchClass", verbose_name=_(u'时段名称'), null=True, default=-1, blank=True) SetTime = models.DateTimeField(_(u'设定时间')) AttTime = models.DateTimeField(_(u'考勤时间')) StatusType = models.SmallIntegerField(_(u'上班签到'), null=True, blank=True, editable=True, default=0, choices=StatusType_enum) class Meta: app_label = 'att' db_table = 'att_record' verbose_name = _(u'考勤记录表') unique_together = (("EmpID", "AttTime"), )
class USER_TEMP_SCH(CachingModel): UserID=EmpForeignKey(db_column='UserID',verbose_name=_(u'人员'), default=1,null=False, blank=False) ComeTime = models.DateTimeField(_(u'开始时间'),null=False, blank=False) LeaveTime = models.DateTimeField(_(u'结束时间'),null=False, blank=False) OverTime = models.IntegerField(_(u'加班时长'),null=False,default=0,blank=True) Type=models.SmallIntegerField(_(u'临时排班类型'),null=True,default=0,blank=True) Flag=models.SmallIntegerField(_(u'当天存在员工排班时'),null=True,default=1,blank=True,editable=True,choices=FLAG) SchclassID=models.IntegerField(null=True,default=1,db_column='SchClassID',blank=True,editable=False) WorkType=models.SmallIntegerField(_(u'工作类型'),default=0,editable=True,choices=WORKTYPE) # SchclassID=models.ForeignKey("SchClass",db_column='SchclassID',verbose_name=_('shift time-table'),null=False,default=-1,blank=True) def save(self): super(USER_TEMP_SCH,self).save() from mysite.att.models.__init__ import get_autocalculate_time as gct from model_waitforprocessdata import WaitForProcessData as wfpd import datetime gct_time=gct() if self.ComeTime<gct_time or self.LeaveTime<=gct_time: wtmp=wfpd() st=self.ComeTime et=self.LeaveTime wtmp.UserID=self.UserID wtmp.starttime=st wtmp.endtime=et #wtmp.customer=self.customer wtmp.save() def __unicode__(self): return u"%s %s"%(self.UserID.PIN,self.UserID.EName) def get_all_Sch_Name(): datas = SchClass.objects.all() sch = [] for row in datas: sch.append (row["SchName"]) return sch class OpClearShift(Operation): help_text=_(u"""清除临时排班记录""") verbose_name=_(u"清除临时排班记录") def action(self): self.object.delete() class dataexport(Operation): help_text = _(u"数据导出") #导出 verbose_name = _(u"临时排班导出") visible = False def action(self): pass class Admin(CachingModel.Admin): default_give_perms=["contenttypes.can_AttUserOfRun"] visible=False list_filter = ('UserID','SchclassID','LeaveTime','ComeTime','OverTime') list_display= ('UserID.PIN','UserID.EName','ComeTime','LeaveTime','WorkType','Flag') search_fields = ['UserID','SchclassID'] class Meta: app_label='att' db_table = 'user_temp_sch' verbose_name=_(u'临时排班') verbose_name_plural=verbose_name unique_together = (("UserID","ComeTime", "LeaveTime"),)
class attShifts(models.Model): ''' 考勤明细表 ''' UserID = EmpForeignKey(verbose_name=_(u'人员'), db_column='userid', null=False) SchIndex = models.IntegerField(db_column='SchIndex', null=True, blank=True) AutoSch = models.SmallIntegerField(db_column='AutoSch', null=True, default=0, editable=False) AttDate = models.DateTimeField(_(u'日期'), db_column='AttDate') #SchId=models.IntegerField(_('SchName'),db_column='SchId', null=True,blank=True) SchId = models.ForeignKey("SchClass", verbose_name=_(u'时段名称'), db_column='SchId', null=True, default=-1, blank=True) ClockInTime = models.DateTimeField(_(u'上班时间'), db_column='ClockInTime') ClockOutTime = models.DateTimeField(_(u'下班时间'), db_column='ClockOutTime') StartTime = models.DateTimeField(_(u'签到时间'), db_column='StartTime', null=True, blank=True) EndTime = models.DateTimeField(_(u'签退时间'), db_column='EndTime', null=True, blank=True) WorkDay = models.FloatField(_(u'应到'), db_column='WorkDay', null=True, blank=True) RealWorkDay = models.FloatField(_(u'实到'), db_column='RealWorkDay', null=True, default=0, blank=True) NoIn = models.SmallIntegerField(_(u'未签到'), db_column='NoIn', null=True, blank=True) NoOut = models.SmallIntegerField(_(u'未签退'), db_column='NoOut', null=True, blank=True) Late = models.FloatField(_(u'迟到'), db_column='Late', null=True, blank=True) Early = models.FloatField(_(u'早退'), db_column='Early', null=True, blank=True) Absent = models.FloatField(_(u'旷工'), db_column='Absent', null=True, blank=True) OverTime = models.FloatField(_(u'加班时间'), db_column='OverTime', null=True, blank=True) WorkTime = models.IntegerField(_(u'出勤时长'), db_column='WorkTime', null=True, blank=True) ExceptionID = models.IntegerField(_(u'例外情况'), db_column='ExceptionID', null=True, blank=True) #----假类ID Symbol = models.CharField(_(u'符号'), db_column='Symbol', max_length=50, null=True, blank=True) MustIn = models.SmallIntegerField(_(u'应签到'), db_column='MustIn', null=True, blank=True) MustOut = models.SmallIntegerField(_(u'应签退'), db_column='MustOut', null=True, blank=True) OverTime1 = models.IntegerField(_(u'加班签到'), db_column='OverTime1', null=True, blank=True) WorkMins = models.IntegerField(_(u'工作分钟'), db_column='WorkMins', null=True, blank=True) SSpeDayNormal = models.FloatField(_(u'平日'), db_column='SSpeDayNormal', null=True, blank=True) SSpeDayWeekend = models.FloatField(_(u'休息日'), db_column='SSpeDayWeekend', null=True, blank=True) SSpeDayHoliday = models.FloatField(_(u'节假日'), db_column='SSpeDayHoliday', null=True, blank=True) AttTime = models.IntegerField(_(u'时段时间(分钟)'), db_column='AttTime', null=True, blank=True) SSpeDayNormalOT = models.FloatField(_(u'平日加班'), db_column='SSpeDayNormalOT', null=True, blank=True) SSpeDayWeekendOT = models.FloatField(_(u'休息日加班'), db_column='SSpeDayWeekendOT', null=True, blank=True) SSpeDayHolidayOT = models.FloatField(_(u'节假日加班'), db_column='SSpeDayHolidayOT', null=True, blank=True) AbsentMins = models.IntegerField(_(u'旷工时间(分钟)'), db_column='AbsentMins', null=True, blank=True) AttChkTime = models.CharField(db_column='AttChkTime', max_length=10, null=True, blank=True) AbsentR = models.FloatField(_(u'旷工'), db_column='AbsentR', null=True, blank=True) ScheduleName = models.CharField(db_column='ScheduleName', max_length=20, null=True, blank=True) IsConfirm = models.SmallIntegerField(db_column='IsConfirm', null=True, blank=True) IsRead = models.SmallIntegerField(db_column='IsRead', null=True, blank=True) Exception = models.CharField(_(u'例外情况明细'), max_length=100, null=True, blank=True) #---请假ID列表 外键到请假明细表 def __unicode__(self): return unicode(u"%s" % (self.UserID)) def get_ExceptionID(self): ''' 计算该考勤日的所有请假及其时长信息(数据来自请假明细表) ''' import datetime from mysite.att.models import LeaveClass, AttException from mysite.iclock.datas import NormalAttValue try: if self.Exception: t = [long(i) for i in self.Exception.split(",")] ex = AttException.objects.filter(UserID=self.UserID, pk__in=t) #----查询出所有请假记录 else: ex = "" if ex: val = {} for e in ex: #---循环所有请假 l = LeaveClass.objects.get(pk=e.ExceptionID) k = u"%s" % l.LeaveName #---假类名称 ad = attShifts.objects.filter(AttDate=self.AttDate, UserID=self.UserID) atttime = 0 for a in ad: atttime = atttime + a.AttTime #---时段时间(分钟) if not val.has_key(k): val[k] = NormalAttValue(e.InScopeTime, l.MinUnit, l.Unit, l.RemaindProc, 1, atttime) else: val[k] = float(val[k]) + float( NormalAttValue(e.InScopeTime, l.MinUnit, l.Unit, l.RemaindProc, 1, atttime)) return ";".join([u"%s:%s" % (k, v) for k, v in val.items()]) else: return "" except: import traceback traceback.print_exc() class Admin(CachingModel.Admin): default_give_perms = [ "contenttypes.can_AttCalculate", ] visible = False list_display = ( 'UserID.pk', 'UserID.DeptID.code', 'UserID.DeptID.name', 'UserID.PIN', 'UserID.EName', 'AttDate|format_date', 'SchId', 'ClockInTime|format_shorttime', 'ClockOutTime|format_shorttime', 'StartTime', 'EndTime', 'WorkDay', 'RealWorkDay', 'MustIn', 'MustOut', 'NoIn', 'NoOut', 'Late', 'Early', 'AbsentR', 'WorkTime', 'get_ExceptionID', 'OverTime', 'WorkMins', 'SSpeDayNormal|format_int', 'SSpeDayWeekend|format_int', 'SSpeDayHoliday|format_int', 'AttTime', 'SSpeDayNormalOT', 'SSpeDayWeekendOT', 'SSpeDayHolidayOT') #newadded_column = { 'ExceptionID':'get_ExceptionID'} class Meta: app_label = 'att' db_table = 'attshifts' verbose_name = _(u'考勤明细表') unique_together = (("UserID", "AttDate", "SchId", "StartTime"), )