Ejemplo n.º 1
0
def pregnant_leave_img_upload_page(request, pk):
    """
    产假证明上传页面
    :param request:
    :return:
    """
    if request.method == 'POST':
        img_str = request.POST.get('img_str')
        sick_leave = Leave.objects.get(pk=pk)
        if img_str and sick_leave:
            sick_leave.attach_photo = img_str
            sick_leave.save()
            # 通知部门考勤员
            applicant_user_id = sick_leave.applicant_openid
            applicant = WXUser.objects.get(wx_openid=applicant_user_id)
            try:
                department_timekeeper = WXUser.objects.get(department=applicant.department, is_timekeeper=1)
                send_msg(receive_open_id=department_timekeeper.wx_openid, applicant_name=applicant.name,
                         start_datetime=sick_leave.leave_start_datetime, end_datetime=sick_leave.leave_end_datetime,
                         _type='产假', days=sick_leave.leave_days, msg_type='产假审核材料')
            except Exception, error:
                print(error)
            return HttpResponse('Success')
        else:
            return HttpResponseServerError()
Ejemplo n.º 2
0
def cancel(request):
    """
    取消自己的请假/外出申请
    :param request:
    :return:
    """
    leave_id = request.POST.get('leave_id', '')
    leave = Leave.objects.get(pk=leave_id)
    all_dealers = leave.all_dealers
    next_dealer_id = leave.next_dealer_id
    leave_days = leave.leave_days
    if leave.type in (0, 8, 9):
        applicant = WXUser.objects.get(wx_openid=leave.applicant_openid)
        if leave.type == 0:
            applicant.legal_vacation_days += leave_days
        if leave.type == 8:
            applicant.company_vacation_days += leave_days
        if leave.type == 9:
            applicant.flexible_vacation_days += leave_days
        applicant.save()
    if next_dealer_id:  # 通知下一个审批者
        next_dealer_user_id = WXUser.objects.get(pk=next_dealer_id).wx_openid
        send_msg(next_dealer_user_id, leave.applicant_name, leave.leave_start_datetime,
                 leave.leave_end_datetime, leave.type, leave.leave_days, 'cancel')
    if all_dealers:  # 通知审批过的人
        for i in all_dealers.split(' '):  # ['test', 'lih']
            send_msg(i, leave.applicant_name, leave.leave_start_datetime,
                     leave.leave_end_datetime, leave.type, leave.leave_days, 'cancel')
    leave.status = 0
    leave.next_dealer_id = None
    leave.save()
    return HttpResponse('Success')
Ejemplo n.º 3
0
def out_apply(request):
    """
    外出post提交
    :param request:
    :return:
    """
    group = request.POST.get('group')
    leave_type = request.POST.get('leave_type', '')
    message = request.POST.get('message', '')
    start_date = request.POST.get('start_date', '')
    end_date = request.POST.get('end_date', '')
    start_time = request.POST.get('start_time', '')
    end_time = request.POST.get('end_time', '')
    leave_days = float(request.POST.get('leave_days_count', 0))
    user_id = request.session.get('user_id')
    wxuser = WXUser.objects.get(wx_openid=user_id)
    create_time = datetime.datetime.now()
    leave_start_datetime = start_date + ' ' + start_time
    leave_end_datetime = end_date + ' ' + end_time

    last_leave = Leave.objects.filter(applicant_openid=user_id).exclude(status=0).last()  # 最后的leave(未取消)
    if last_leave:
        last_leave_start_time = last_leave.leave_start_datetime
        last_leave_end_time = last_leave.leave_end_datetime
        start_datetime = datetime.datetime.strptime(start_date + ' ' + start_time, '%Y-%m-%d %H:%M')
        end_datetime = datetime.datetime.strptime(end_date + ' ' + end_time, '%Y-%m-%d %H:%M')

        # 申请开始时间或者结束时间在最后条记录中,不能再申请
        if not ((end_datetime < last_leave_start_time) or (start_datetime > last_leave_end_time)):
            return HttpResponse(json.dumps({'leave_type': 'Not Allowed'}))

    # 存在未销假的假期
    # if Leave.objects.filter(applicant_openid=user_id, status=3, group=1).exists():
    #     return HttpResponse(json.dumps({'leave_type': 'Exists leave not completed'}))

    Leave.objects.create(department=wxuser.department, group=int(group), type=leave_type, leave_start_datetime=leave_start_datetime,
                         leave_end_datetime=leave_end_datetime, create_time=create_time, leave_days=leave_days,
                         leave_reason=message, remark='', applicant_name=wxuser.name, applicant_openid=wxuser.wx_openid,
                         status=1, next_dealer=wxuser.direct_director, refuse_reason='')

    # send Email
    direct_director = WXUser.objects.get(pk=wxuser.direct_director.pk)
    direct_director_email = direct_director.email
    direct_director_name = direct_director.name
    # send_email('*****@*****.**', direct_director_email, direct_director_name, wxuser.name, leave_start_datetime,
    #            leave_end_datetime, leave_days, '外出', 'apply')
    send_msg(receive_open_id=direct_director.wx_openid, applicant_name=wxuser.name,
             start_datetime=str(leave_start_datetime),
             end_datetime=str(leave_end_datetime), _type='外出' + LEAVE_TYPE_DICT[int(leave_type)], days=leave_days,
             msg_type='apply')
    return HttpResponse(json.dumps({'leave_type': 'Success'}))
Ejemplo n.º 4
0
def approve(request):
    """
    批准
    :param request:
    :return:
    """
    leave_id = request.POST.get('leave_id', '')
    next_dealer_id = int(request.POST.get('next_dealer_id'))
    next_dealer = WXUser.objects.get(pk=next_dealer_id)
    applicant_wx_openid = request.POST.get('applicant_wx_openid', '')
    result = request.POST.get('result', '')
    refuse_reason = request.POST.get('refuse_reason', '')
    applicant_wx_user = WXUser.objects.get(wx_openid=applicant_wx_openid)
    direct_director_id = applicant_wx_user.direct_director_id
    direct_director = WXUser.objects.get(pk=direct_director_id)
    dept_leader_id = applicant_wx_user.dept_leader_id
    dept_leader = WXUser.objects.get(pk=dept_leader_id)
    leave = Leave.objects.get(pk=leave_id)
    if result == 'agree':  # 同意
        if leave.group == 1:  # 同意请假
            if leave.type in (2, 3) and WXUser.objects.get(id=next_dealer_id).is_timekeeper == 1:
                # 考勤员审核病产假通过后传给直接主管

                leave.next_dealer_id = direct_director
                send_msg(receive_open_id=direct_director.wx_openid, applicant_name=applicant_wx_user.name,
                         start_datetime=str(leave.leave_start_datetime),
                         end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                         days=leave.leave_days,  msg_type='agree')
            # 先判断是不是部门领导,如果判断是的话就直接通过了,有可能部门领导和直接主管是同一人
            elif int(applicant_wx_user.dept_leader_id) == next_dealer_id:  # 第二级审批, 即部门领导审批
                if leave.leave_days > 1 and leave.type == 1:  # 部门领导审批通过, 如果是事假且大于1天,跳转通知HR部门审批
                    leave.next_dealer_id = 999  # todo 先假设HR审批账号id为999
                    # send_email('*****@*****.**', 'HR@com', applicant_wx_user.name,  # todo HR邮箱待填写
                    #            applicant_wx_user.name, leave.leave_start_datetime, leave.leave_end_datetime,
                    #            leave.leave_days, '请假' if leave.group == 1 else '外出', 'agree')
                    send_msg(receive_open_id='lih', applicant_name=applicant_wx_user.name,
                             start_datetime=str(leave.leave_start_datetime),
                             end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                             days=leave.leave_days,  msg_type='agree')

                # 部门领导审批通过
                else:
                    leave.next_dealer_id = None
                    leave.status = 3
                    leave.deal_end_time = datetime.datetime.now()
                    # 发邮件给申请者, 通知审批通过
                    # send_email('*****@*****.**', applicant_wx_user.email, applicant_wx_user.name,
                    #            applicant_wx_user.name, leave.leave_start_datetime, leave.leave_end_datetime,
                    #            leave.leave_days, '请假' if leave.group == 1 else '外出', 'agree')
                    send_msg(receive_open_id=applicant_wx_user.wx_openid, applicant_name=applicant_wx_user.name,
                             start_datetime=str(leave.leave_start_datetime),
                             end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                             days=leave.leave_days,  msg_type='approve')

            elif int(applicant_wx_user.direct_director_id) == next_dealer_id:  # 第一级审批, 即直接主管审批
                leave.next_dealer_id = dept_leader_id
                # 发邮件给直接主管审批
                # send_email('*****@*****.**', dept_leader.email, dept_leader.name, applicant_wx_user.name,
                #            leave.leave_start_datetime, leave.leave_end_datetime, leave.leave_days,
                #            '请假' if leave.group == 1 else '外出', 'apply')
                send_msg(receive_open_id=dept_leader.wx_openid, applicant_name=applicant_wx_user.name,
                         start_datetime=str(leave.leave_start_datetime),
                         end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                         days=leave.leave_days,  msg_type='agree')

            elif leave.next_dealer_id == 999 and leave.type == 1:  # todo HR审批大于1天的事假
                leave.next_dealer_id = None
                leave.status = 3
                leave.deal_end_time = datetime.datetime.now()
                # 发邮件给申请者, 通知审批通过
                # send_email('*****@*****.**', applicant_wx_user.email, applicant_wx_user.name,
                #            applicant_wx_user.name, leave.leave_start_datetime, leave.leave_end_datetime,
                #            leave.leave_days, '请假' if leave.group == 1 else '外出', 'agree')

                send_msg(receive_open_id=applicant_wx_user.wx_openid, applicant_name=applicant_wx_user.name,
                         start_datetime=str(leave.leave_start_datetime),
                         end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                         days=leave.leave_days,  msg_type='approve')

        else:  # 同意外出

            leave.next_dealer_id = None
            leave.status = 3
            leave.deal_end_time = datetime.datetime.now()
            # 发邮件给申请者, 通知审批通过
            # send_email('*****@*****.**', applicant_wx_user.email, applicant_wx_user.name,
            #            applicant_wx_user.name, leave.leave_start_datetime, leave.leave_end_datetime,
            #            leave.leave_days, '请假' if leave.group == 1 else '外出', 'agree')
            send_msg(receive_open_id=applicant_wx_user.wx_openid, applicant_name=applicant_wx_user.name,
                     start_datetime=str(leave.leave_start_datetime),
                     end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                     days=leave.leave_days,  msg_type='approve')

            if applicant_wx_user.is_leader == 1:  # 中层领导外出需发邮件给HR
                # send_email('*****@*****.**', 'HR@com', applicant_wx_user.name,  # todo HR邮箱待填写
                #            applicant_wx_user.name, leave.leave_start_datetime, leave.leave_end_datetime,
                #            leave.leave_days, '请假' if leave.group == 1 else '外出', 'agree')
                send_msg(receive_open_id='lih', applicant_name=applicant_wx_user.name,
                         start_datetime=str(leave.leave_start_datetime),
                         end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                         days=leave.leave_days,  msg_type='approve')
        # 同意后加入 all_dealers
        leave.all_dealers += (next_dealer.wx_openid + ' ')
        leave.save()
        return HttpResponse('Agree')

    else:
        # 拒绝
        # 发邮件给申请者, 通知审批未通过
        # send_email('*****@*****.**', applicant_wx_user.email, applicant_wx_user.name, applicant_wx_user.name,
        #            leave.leave_start_datetime, leave.leave_end_datetime, leave.leave_days,
        #            '请假' if leave.group == 1 else '外出', 'reject')
        send_msg(receive_open_id=applicant_wx_user.wx_openid, applicant_name=applicant_wx_user.name,
                 start_datetime=str(leave.leave_start_datetime),
                 end_datetime=str(leave.leave_end_datetime), _type='请假' if leave.group == 1 else '外出',
                 days=leave.leave_days,  msg_type='reject')

        # 拒绝后加入 all_dealers

        leave.all_dealers += (next_dealer.wx_openid + ' ')

        leave.next_dealer_id = None
        leave.status = 2
        leave.deal_end_time = datetime.datetime.now()
        leave.refuse_reason = refuse_reason
        leave.save()
        if leave.type == 0:  # 拒绝年假后需给申请者补上年假数
            applicant_wx_user.legal_vacation_days += leave.leave_days
        elif leave.type == 8:
            applicant_wx_user.flexible_vacation_days += leave.leave_days
        applicant_wx_user.save()
        return HttpResponse('Reject')
Ejemplo n.º 5
0
        last_leave_end_time = last_leave.leave_end_datetime
        start_datetime = datetime.datetime.strptime(start_date + ' ' + start_time, '%Y-%m-%d %H:%M')
        end_datetime = datetime.datetime.strptime(end_date + ' ' + end_time, '%Y-%m-%d %H:%M')

        # 申请开始时间或者结束时间在最后条记录中,不能再申请
        if not ((end_datetime < last_leave_start_time) or (start_datetime > last_leave_end_time)):
            return HttpResponse(json.dumps({'leave_type': 'Not Allowed'}))
        # 存在未销假的假期
        if Leave.objects.filter(applicant_openid=user_id, status=3, group=1).exists():
            last_leave = Leave.objects.filter(applicant_openid=user_id, status=3, group=1).last()
            if last_leave.leave_end_datetime < datetime.datetime.now():
                return HttpResponse(json.dumps({'leave_type': 'Exists leave not completed'}))
    if group == '1' and leave_type in ('2', '3'):  # 病假or产假 , 返回新增leave_id用于上传图片页面
        if leave_days >= 5:  # 病假超5天或者产假通知李赫
            send_msg('lih', applicant_name=wxuser.department+'部门'+wxuser.name, start_datetime=str(leave_start_datetime),
                     end_datetime=str(leave_end_datetime), _type=LEAVE_TYPE_DICT[int(leave_type)],
                     days=leave_days, msg_type='长病假/产假')
        new_leave_id = Leave.objects.create(department=wxuser.department, group=int(group), type=leave_type,
                                            leave_start_datetime=leave_start_datetime,
                                            leave_end_datetime=leave_end_datetime, create_time=create_time,
                                            leave_days=leave_days, leave_reason=message, remark='',
                                            applicant_name=wxuser.name, applicant_openid=wxuser.wx_openid,
                                            status=1,
                                            next_dealer=department_timekeeper,
                                            refuse_reason='').id
        # 病产假通知部门考勤员准备查看申请资料
        send_msg(receive_open_id=department_timekeeper.wx_openid, applicant_name=wxuser.name,
                 start_datetime=str(leave_start_datetime),
                 end_datetime=str(leave_end_datetime), _type=LEAVE_TYPE_DICT[int(leave_type)],
                 days=leave_days, msg_type='sick_apply' if leave_type == '2' else 'pregnant_apply')
        if leave_type == '2':