class OpAddMeetingEmp(ModelOperation): visible = True verbose_name = _(u"添加会议人员") help_text = _(u"新增会议人员") params = ( ('meeting', MeetingForeignKey(verbose_name=_(u'会议'))), ('user', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True)), ) def action(self, user, meeting): # print "len(user)",len(user) if len(user) < 1: raise Exception(_(u'请选择人员')) if self.request: ce = MeetingEmp.objects.filter(user__in=user, meetingID=meeting) if ce.count() > 0: raise Exception( _(u'%s %s 已经添加到该会议') % (ce[0].user.PIN, ce[0].user.EName)) limit = meeting.roomMeeting.empLimit if len(user) > limit: raise Exception(_(u'已超过会议室的最大容量(%s)') % limit) meetngE = MeetingEmp.objects.filter(meetingID=meeting) if len(meetngE) + len(user) > limit: raise Exception(_(u'已超过会议室的最大容量(%s)') % limit) st = meeting.startTime et = meeting.endTime me_f = list( MeetingEntity.objects.filter(startTime__year=et.year, startTime__month=et.month, startTime__day=et.day, startTime__lt=et, endTime__gt=st)) me_s = list( MeetingEntity.objects.filter(startTime__year=et.year, startTime__month=et.month, startTime__day=et.day, startTime__gt=st, endTime__lt=et)) emp_have = MeetingEmp.objects.filter(meetingID__in=list(me_f + me_s)) empHave = [] for emp in emp_have: e = Employee.objects.get(PIN__iexact=emp.PIN) empHave.append(e.PIN) for emp in user: e = Employee.objects.get(pk__iexact=emp.pk) if e.PIN in empHave: raise Exception( _(u"%s 在这个会议时间段已参加其他会议,无法参加此次会议") % emp) ck = MeetingEmp() ck.user = emp ck.PIN = emp.PIN ck.EName = emp.EName ck.meetingID = meeting ck.save()
class OpAddManyOvertime(ModelOperation): help_text = _(u'''新增''') verbose_name = _(u"新增加班单") params = ( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True, null=True)), ('starttime', models.DateTimeField(_(u'开始时间'), null=False, blank=False)), ('endtime', models.DateTimeField(_(u'结束时间'), null=False, blank=False)), ('remark', models.CharField(_(u'加班描述'), null=True, blank=True, max_length=200)), ) def action(self, **args): emps = args.pop('UserID') if args['starttime'] >= args['endtime']: raise Exception(_(u'结束时间不能小于等于开始时间')) if not emps: raise Exception(_(u'请选择人员')) if len(emps) > 1000: raise Exception(_(u'人员选择过多,最大支持1000人同时新增记录!')) for emp in emps: OverTime(emp=emp, **args).save()
class OpAddManyCheckExact(ModelOperation): verbose_name=_(u"新增补签卡") help_text=_(u'新增补签卡同时会在原始记录表中增加一条相同记录,修改时会同时修改原始记录表中的相同记录') params=( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'),blank=True,null=True)), ('checktime',models.DateTimeField(_(u'签卡时间'))), ('checktype',models.CharField(_(u'考勤状态'), choices=ATTSTATES)), ('reason',models.CharField(_(u'签卡原因'),blank=True,null=True,max_length=100)), ) def action(self,UserID,checktime,checktype,reason): if self.request: if UserID==0: depts=self.request.POST.getlist('deptIDs') UserID=Employee.objects.filter(DeptID__in=depts) if not UserID: raise Exception(_(u'请选择人员')) ce=CheckExact.objects.filter(UserID__in=UserID,CHECKTIME=checktime) if ce.count()>0: raise Exception(_(u'补签记录输入重复')) for emp in UserID: ck=CheckExact() ck.UserID=emp ck.CHECKTIME=checktime ck.YUYIN=reason ck.CHECKTYPE=checktype ck.save()
class OpAddManyObj(ModelOperation): verbose_name = _(u'新增') help_text = _(u'新增') params = ( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), null=True, blank=True)), ('starttime', models.DateTimeField(_(u'开始时间'), blank=False, null=False)), ('endtime', models.DateTimeField(_(u'结束时间'), blank=False, null=False)), # ('atttype',models.SmallIntegerField(_(u'考勤类型'),default=2,choices=ATTTYPE,blank=False,null=False)), ) def action(self, UserID, starttime, endtime): users = UserID if self.request: if not users: raise Exception(u"%s" % _(u'请选择人员')) if len(users) > 1000: raise Exception(_(u'人员选择过多,最大支持1000人同时新增记录!')) for u in users: sua = SetUserAtt() sua.UserID = u sua.starttime = starttime sua.endtime = endtime # sua.atttype=atttype sua.save()
class OpAddManyUserID(ModelOperation): help_text = _(u'''新增''') verbose_name = _(u"新增请假") params = ( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), blank=False, null=False)), ('start', models.DateTimeField(_(u'开始时间'))), ('end', models.DateTimeField(_(u'结束时间'))), ('leaveclass', models.ForeignKey(LeaveClass, verbose_name=_(u'假类'))), ('reson', models.CharField(_(u'请假原因'), blank=True, null=True, max_length=100)), ('apply', models.DateTimeField(_(u'填写时间'), default=datetime.datetime.now(), blank=True)), ) def action(self, **args): emps = args.pop('UserID') if self.request: if not emps: depts = self.request.POST.getlist('deptIDs') emps = Employee.objects.filter(DeptID__in=depts) if args['start'] >= args['end']: raise Exception(_(u'结束时间不能小于开始时间')) if not emps: raise Exception(_(u'请选择人员')) for emp in emps: EmpSpecDay(emp=emp, **args).save()
class OpAddManyUserID(ModelOperation): help_text = _(u'''新增''') verbose_name = _(u"新增请假") params = ( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True, null=True)), ('start', models.DateTimeField(_(u'开始时间'))), ('end', models.DateTimeField(_(u'结束时间'))), ('leaveclass', models.ForeignKey(LeaveClass, verbose_name=_(u'假类'))), ('reson', models.CharField(_(u'请假原因'), blank=True, null=True, max_length=100)), ('apply', models.DateTimeField(_(u'填写时间'), default=datetime.datetime.now, blank=True)), ) def action(self, **args): from mysite.iclock.iutils import get_dept_from_all, get_max_in emps = args.pop('UserID') if args['start'] >= args['end']: raise Exception(_(u'结束时间不能小于开始时间')) if not emps: raise Exception(_(u'请选择人员')) if len(emps) > 1000: raise Exception(_(u'人员选择过多,最大支持1000人同时新增记录!')) for emp in emps: EmpSpecDay(emp=emp, **args).save()
class OpAddManyObj(ModelOperation): verbose_name=_(u'新增') help_text=_(u'新增') params=( ('UserID',EmpMultForeignKey(verbose_name=_(u'人员'),null=True,blank=True)), ('starttime',models.DateTimeField(_(u'开始时间'),blank=False,null=False)), ('endtime',models.DateTimeField(_(u'结束时间'),blank=False,null=False)), ('atttype',models.SmallIntegerField(_(u'考勤类型'),default=2,choices=ATTTYPE,blank=False,null=False)), ) def action(self,UserID,starttime,endtime,atttype): users=[] if self.request: deptIDs=self.request.POST.getlist('deptIDs') UserIDs=self.request.POST.getlist('UserID') if deptIDs: users=Employee.objects.filter(DeptID__in=deptIDs) elif UserIDs: users=Employee.objects.filter(pk__in=UserIDs) if not users: raise Exception(u"%s"%_(u'请选择人员')) for u in users: sua=SetUserAtt() sua.UserID=u sua.starttime=starttime sua.endtime=endtime sua.atttype=atttype sua.save()
class OpUpEmpInfo(ModelOperation): help_text=_(u'''手动上传设备上的用户的基本信息(如果即没选择人员也没填写人员编号则默认从所有设备上传所有用户基本信息)''') verbose_name=_(u"上传用户信息") perm_model_menu = ['att.AttDeviceDataManage'] params=( ('user' , EmpMultForeignKey(verbose_name=_(u'选择人员'),null=True, blank=True)), ('PIN' , models.CharField(_(u'或者填写人员编号'), max_length=9,null=True, blank=True)), ) def action(self, **args): users=[] users = args['user'] print 'users:',users if self.request: depts=self.request.POST.getlist('deptIDs') if len(depts)>0: users=Employee.objects.filter(DeptID__in=depts) pin = None if len(args['PIN'])>0: try: pin = str(int(args['PIN'])) except: raise Exception(_(u'人员编号只能为数字')) if int(args['PIN']) == 0: raise Exception(_(u'人员编号不能为0')) if len(args['PIN']) > settings.PIN_WIDTH: raise Exception(_(u'%(f)s 人员编号长度不能超过%(ff)s位') % {"f":args['PIN'], "ff":settings.PIN_WIDTH}) pin = format_pin(args['PIN']) push_emp_cmd(users,pin)
def __init__(self, obj): super(AccLevelSet.OpAddEmpToLevel, self).__init__(obj) self.params.append(('level_id', models.IntegerField(_(u'权限ID'), null=True, blank=True, default=obj.id))) self.params.append(('emps', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True, null=True)))
class OpAddAllowance(ModelOperation): verbose_name = _(u"补贴登记") if get_option("POS_ID"): help_text = _( u'新增的补贴数据需要审核才真正下发到每个人员。卡状态为挂失,停用,过期的人员不能进行补贴登记,系统自动过滤') else: help_text = _( u'新增的补贴数据需要审核才真正下发到每个人员。卡状态为挂失,过期的人员不能进行补贴登记,已登记卡账号的人员,每个月只允许登记一次补贴,系统自动过滤' ) params = [ ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True, null=True)), ('money', models.DecimalField(_(u'补贴金额'), max_digits=8, decimal_places=2)), ('remark', models.CharField(_(u'备注'), blank=True, null=True, max_length=100)), ] def __init__(self, obj): super(Allowance.OpAddAllowance, self).__init__(obj) if get_option("POS_IC"): self.params.append( ('valid_date', models.DateField(verbose_name=_(u'补贴有效日期')))) def action(self, **args): from mysite.personnel.models.model_emp import Employee from mysite.personnel.models.model_issuecard import IssueCard, CARD_VALID, CARD_STOP, CARD_LOST, CARD_OVERDUE, POS_CARD emps = args.pop('UserID') if len(emps) > 1000: raise Exception( _(u'人员选择过多,最大支持1000人同时登记补贴!超出范围的情况下,请使用补贴导入功能!', )) if not emps: raise Exception(_(u'请选择所需补贴人员!')) if args['money'] == 0: raise Exception(_(u'补贴金额不能为0')) if args['money'] < 0: raise Exception(_(u'补贴金额不能为负数')) now = datetime.datetime.now().date() if get_option("POS_IC") and now > args['valid_date']: raise Exception(_(u"有效日期必须大于当前日期")) for emp in emps: Allowance(user=emp, **args).save()
class OpAddUserOfRun(ModelOperation): help_text = _(u"""新增员工排班""") verbose_name = _(u"新增排班") params = ( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True, null=True)), ('StartDate', models.DateField( _(u'开始日期'), default=datetime.datetime.now().strftime("%Y-%m-01"))), ('EndDate', models.DateField( _(u'结束日期'), default=(datetime.datetime.now() + datetime.timedelta(days=31)).strftime("%Y-%m") + "-01")), ) def action(self, UserID, StartDate, EndDate): # from mysite.personnel.models.model_emp import Employee # deptIDs=self.request.POST.getlist('deptIDs') # UserIDs=self.request.POST.getlist('UserID') # dept_all=self.request.POST.get('dept_all','') # if len(UserIDs)>0: # users=Employee.objects.filter(id__in=UserIDs) # else: # if dept_all: # users=Employee.objects.filter(DeptID__in=deptIDs) # else: # users=[] users = UserID # print users if not users: raise Exception(_(u'请选择人员')) if len(users) > 1000: raise Exception(_(u'人员选择过多,最大支持1000人同时新增记录!')) sAssigned_shifts = self.request.POST.get('sAssigned_shifts', '') #print "sAssigned_shifts:%s"%sAssigned_shifts if not sAssigned_shifts: raise Exception(_(u'请选择班次')) if StartDate > EndDate: raise Exception(_(u'结束日期不能小于开始日期!')) sAssigned_shifts = eval(sAssigned_shifts) print sAssigned_shifts[0] num_run = NUM_RUN.objects.get(pk=int(sAssigned_shifts[0]['SchId'])) for u in users: USER_OF_RUN.objects.filter(UserID=u, StartDate=StartDate, EndDate=EndDate, NUM_OF_RUN_ID=num_run).delete() t = USER_OF_RUN() t.UserID = u t.StartDate = StartDate t.EndDate = EndDate t.NUM_OF_RUN_ID = num_run t.save() from mysite.att.models.__init__ import get_autocalculate_time as gct from model_waitforprocessdata import WaitForProcessData as wfpd import datetime gct_time = gct() gct_date = datetime.date(gct_time.year, gct_time.month, gct_time.day) if StartDate < gct_date or EndDate <= gct_date: wtmp = wfpd() st = datetime.datetime(StartDate.year, StartDate.month, StartDate.day, 0, 0, 0) et = datetime.datetime(EndDate.year, EndDate.month, EndDate.day, 23, 59, 59) wtmp.UserID = u wtmp.starttime = st wtmp.endtime = et #wtmp.customer=self.customer wtmp.save()
class OpAddTempShifts(ModelOperation): from mysite.att.models.user_temp_sch import USER_TEMP_SCH help_text = _(u"""新增员工临时排班""") verbose_name = _(u"新增临时排班") params = ( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True, null=True)), ('StartDate', models.DateField( _(u'开始日期'), default=datetime.datetime.now().strftime("%Y-%m-%d"))), ('EndDate', models.DateField( _(u'结束日期'), default=(datetime.datetime.now() + datetime.timedelta(days=1)).strftime("%Y-%m-%d"))), ('WorkType', USER_TEMP_SCH._meta.get_field('WorkType')), ) def action(self, UserID, StartDate, EndDate, WorkType): from mysite.personnel.models.model_emp import Employee from mysite.att.models.schclass import SchClass from mysite.att.models.user_temp_sch import USER_TEMP_SCH import datetime from mysite.personnel.models import Department if self.request: #addTemparyShifts(self.request) st = self.request.POST.get('StartDate', "") et = self.request.POST.get('EndDate', "") start = st.replace("/", "-") endt = et.replace("/", "-") chklbSchClass = self.request.POST.getlist("sTimeTbl") chklbDates = self.request.POST.getlist("sDates") OverTime = self.request.POST.get('OverTime', '') users = UserID flag = self.request.POST.get('Flag', '1') #print 'flag:%s'%flag is_OT = self.request.POST.get('is_OT', '') is_OT = (str(is_OT) == 'on') # #获取用户 # if len(UserIDs)>0: # users=Employee.objects.filter(id__in=UserIDs) # else: # if dept_all: # users=Employee.objects.filter(DeptID__in=deptIDs) # else: # users=[] if not users: raise Exception(_(u'请选择人员')) if len(users) > 1000: raise Exception(_(u'人员选择过多,最大支持1000人同时新增记录!')) if not chklbDates: raise Exception(_(u'请选择日期')) if not chklbSchClass: raise Exception(_(u'请选择时段')) #获取时间段 schs = SchClass.objects.filter(pk__in=chklbSchClass) # for sch in schs: # st=datetime.strptime(start+' '+ sch.StartTime.strftime('%H:%M:%S'),"%Y-%m-%d %H:%M:%S") # et=datetime.strptime(endt+' '+ sch.EndTime.strftime('%H:%M:%S'),"%Y-%m-%d %H:%M:%S") # # for u in users: # # sql="delete from %s where UserID=%s and SchClassID=%s and ComeTime>='%s' and LeaveTime<='%s'"%( USER_TEMP_SCH._meta.db_table, # u.pk,sch.pk,st.strftime("%Y-%m-%d %H:%M:%S"),et.strftime("%Y-%m-%d %H:%M:%S")) # print "sql:%s"%sql # customSql(sql) # #循环保存临时排班 for day in chklbDates: day = day.replace("/", "-") for sch in schs: #格式化时间 st = datetime.datetime.strptime( day + ' ' + sch.StartTime.strftime('%H:%M:%S'), '%Y-%m-%d %H:%M:%S') et = datetime.datetime.strptime( day + ' ' + sch.EndTime.strftime('%H:%M:%S'), '%Y-%m-%d %H:%M:%S') if et < st: #判断时间段是否跨天 et = et + datetime.timedelta(days=1) #清除已经排过的临时排班 #USER_TEMP_SCH.objects.filter(UserID__in=users,SchclassID__exact=sch.pk,ComeTime__exact=st,LeaveTime__exact=et).delete() #保存 for u in users: USER_TEMP_SCH.objects.filter( UserID__exact=u, SchclassID__exact=sch.pk, ComeTime__exact=st, LeaveTime__exact=et).delete() t = USER_TEMP_SCH() t.UserID = u t.ComeTime = st t.LeaveTime = et t.WorkType = WorkType t.Flag = flag if is_OT: t.OverTime = OverTime t.SchclassID = sch.pk t.save()
class AccFirstOpen(CachingModel): u""" 首卡常开 """ door = models.ForeignKey(AccDoor, verbose_name=_(u'门名称'), default=1, editable=True, null=True) timeseg = models.ForeignKey(AccTimeSeg, verbose_name=_(u'门禁时间段'), editable=True, null=True) #, default=1 emp = EmpMultForeignKey(verbose_name=_(u'人员'), null=True, blank=True, editable=False) def limit_accfirstopen_to(self, queryset, user): #self 为class #需要过滤掉用户权限不能控制的首卡开门人员组(列表datalist) da = user.deptadmin_set.all() if not user.is_superuser and da: #非超级用户如果a不为空则默认全部区域 d_limit = [int(d.dept_id) for d in da] emps = Employee.objects.exclude(DeptID__in=d_limit) queryset = queryset.exclude(emp__in=emps) return queryset def __unicode__(self): return u"%s" % self.door def save(self, *args, **kwargs): super(AccFirstOpen, self).save() #log_msg=False def delete(self): sync_delete_firstcard(self.door) super(AccFirstOpen, self).delete() self.door.device.check_firstcard_options(self.door) def get_count(self): return self.emp.all().count() def data_valid(self, sendtype): door = AccDoor.objects.get( pk=self.door.pk) #get the door object.sure to exist if sendtype == SAVETYPE_EDIT: obj = AccFirstOpen.objects.filter(id=self.id)[0] if obj.timeseg_id != self.timeseg_id: if self.timeseg_id in [ a.timeseg_id for a in door.accfirstopen_set.all().exclude( timeseg=obj.timeseg_id) ]: #如果当前时间段已经存在于该门设定时间段内(自身除外)。 raise Exception(_(u'当前用户或其他用户已添加过该门在当前时间段内的首卡常开设置')) obj.timeseg_id = self.timeseg_id else: #新增 if self.timeseg_id in [ a.timeseg_id for a in door.accfirstopen_set.all() ]: #如果当前时间段已经存在于该门设定时间段内。 raise Exception(_(u'当前用户或其他用户已添加过该门在当前时间段内的首卡常开设置')) class OpDelEmpFromFCOpen(Operation): verbose_name = _(u"删除开门人员") def action(self): pass class OpAddEmpToFCOpen(Operation): verbose_name = _(u"添加开门人员") help_text = _(u"""添加具有首卡常开权限人员。""") def action(self): dept_all = self.request.POST.getlist("dept_all") #'on'或者'' if not dept_all: emps = set(self.request.POST.getlist( "mutiple_emp")) #添加时mutiple_emp,新增时emp else: #勾选 选择部门下所有人员时 dept_id = self.request.POST.getlist("deptIDs") #print '---accfirstopen--dept_id=',dept_id emps = [ e.id for e in Employee.objects.filter(DeptID__in=dept_id) ] old_emps = [o.id for o in self.object.emp.all()] for e in emps: if int(e) not in old_emps: #已添加的不再添加 self.object.emp.add(e) sync_set_firstcard(self.object.door) class Admin(CachingModel.Admin): help_text = _(u'系统不允许存在该门在当前时间段内重复的首卡常开设置。') menu_group = 'acc_doorset_' menu_focus = 'DoorSetPage' parent_model = 'AccDoor' menu_index = 100028 list_display = ('timeseg', 'foemp_count') newadded_column = {'foemp_count': 'get_count'} #newadded_column = { 'employees': 'get_emp' } position = _(u"门禁系统 -> 门设置 -> 首卡常开设置") disabled_perms = [ 'clear_accfirstopen', 'dataimport_accfirstopen', 'dataexport_accfirstopen', 'view_accfirstopen', 'clear_accfirstopen' ] #hide_perms = ["opaddemptofcopen_accfirstopen"] #select_related_perms = {"browse_accfirstopen": "opaddemptofcopen_accfirstopen"} class Meta: app_label = 'iaccess' db_table = 'acc_firstopen' verbose_name = _(u'首卡常开设置') verbose_name_plural = verbose_name
class OpAddTempShifts(ModelOperation): from mysite.att.models.user_temp_sch import USER_TEMP_SCH help_text = _(u"""新增员工临时排班""") verbose_name = _(u"新增临时排班") params = ( ('UserID', EmpMultForeignKey(verbose_name=_(u'人员'), blank=True, null=True)), ('StartDate', models.DateField( _(u'开始日期'), default=datetime.datetime.now().strftime("%Y-%m-%d"))), ('EndDate', models.DateField( _(u'结束日期'), default=(datetime.datetime.now() + datetime.timedelta(days=1)).strftime("%Y-%m-%d"))), ('WorkType', USER_TEMP_SCH._meta.get_field('WorkType')), ) def action(self, UserID, StartDate, EndDate, WorkType): from mysite.att.models.schclass import SchClass from mysite.att.models.user_temp_sch import USER_TEMP_SCH import datetime from mysite.personnel.models import Department if self.request: st = self.request.POST.get('StartDate', "") et = self.request.POST.get('EndDate', "") start = st.replace("/", "-") endt = et.replace("/", "-") chklbSchClass = self.request.POST.getlist("sTimeTbl") chklbDates = self.request.POST.getlist("sDates") OverTime = self.request.POST.get('OverTime', '') deptIDs = self.request.POST.getlist('deptIDs') UserIDs = self.request.POST.getlist('UserID') dept_all = self.request.POST.get('dept_all', '') flag = self.request.POST.get('Flag', '1') is_OT = self.request.POST.get('is_OT', '') is_OT = (str(is_OT) == 'on') if len(UserIDs) > 0: users = Employee.objects.filter(id__in=UserIDs) else: if dept_all: users = Employee.objects.filter(DeptID__in=deptIDs) else: users = [] if not users: raise Exception(_(u'请选择人员')) if not chklbDates: raise Exception(_(u'请选择日期')) if not chklbSchClass: raise Exception(_(u'请选择时段')) #获取时间段 schs = SchClass.objects.filter(pk__in=chklbSchClass) #循环保存临时排班 for day in chklbDates: day = day.replace("/", "-") for sch in schs: #格式化时间 st = datetime.datetime.strptime( day + ' ' + sch.StartTime.strftime('%H:%M:%S'), '%Y-%m-%d %H:%M:%S') et = datetime.datetime.strptime( day + ' ' + sch.EndTime.strftime('%H:%M:%S'), '%Y-%m-%d %H:%M:%S') if et < st: #判断时间段是否跨天 et = et + datetime.timedelta(days=1) #保存 for u in users: USER_TEMP_SCH.objects.filter( UserID__exact=u, SchclassID__exact=sch.pk, ComeTime__exact=st, LeaveTime__exact=et).delete() t = USER_TEMP_SCH() t.UserID = u t.ComeTime = st t.LeaveTime = et t.WorkType = WorkType t.Flag = flag if is_OT: t.OverTime = OverTime t.SchclassID = sch.pk t.save()