示例#1
0
def create_holiday():
    json_holiday = request.json
    holiday_type = json_holiday.get('holiday_type')
    holiday_time_begin = json_holiday.get('holiday_time_begin')
    holiday_time_end = json_holiday.get('holiday_time_end')
    reason = json_holiday.get('holiday_reason')
    worker_id = g.current_user.id

    male = g.current_user.male
    print(male)

    if (male == True and holiday_type == str(
            HolidayType.query.filter(HolidayType.name == '产假').first().id)):
        return bad_request("男性不能请产假")

    if (male == False and holiday_type == str(
            HolidayType.query.filter(HolidayType.name == '陪产假').first().id)):
        return bad_request("女性不能请陪产假")

    holiday = Holiday(type=holiday_type,
                      worker_id=worker_id,
                      holiday_time_begin=holiday_time_begin,
                      holiday_time_end=holiday_time_end,
                      apply_time=datetime.now(),
                      reason=reason)

    add_to_db(holiday)

    if holiday.holiday_time_begin > holiday.holiday_time_end:
        delete_to_db(holiday)
        return bad_request('begin is latter than end')

    if holiday.holiday_time_begin <= datetime.now():
        delete_to_db(holiday)
        return bad_request('begin must latter than todays')

    if reason is None or reason == "":
        delete_to_db(holiday)
        return bad_request('you need reason to apply')

    if HolidayType.query.get(holiday_type) is None:
        delete_to_db(holiday)
        return bad_request('the holiday type not exit')

    if holiday.type == 2:
        long = (holiday.holiday_time_end - holiday.holiday_time_begin).days
        if holiday.worker.year_holidays_residue < long:
            delete_to_db(holiday)
            return bad_request("your annual leave nums isn't enough")
        else:
            sub_residue(holiday.worker, long)

    add_to_db(holiday)
    return jsonify({'holiday_id': holiday.id}), 201
示例#2
0
def modify_the_workadd(id):
    workadd = WorkAdd.query.filter(WorkAdd.id == id).first()

    if workadd is None:
        return bad_request("the workadd isn't exit")

    if workadd.worker_id != g.current_user.id:
        return bad_request("your can't modify the holiday isn't belong you")

    if workadd.add_state == 1 or workadd.add_state == -1:
        return bad_request("your can't modify the workadd is ok or cancel")

    json_workadd = request.json
    add_start = json_workadd.get('workadd_start')
    add_end = json_workadd.get('workadd_end')
    add_reason = json_workadd.get('workadd_reason')
    add_type = json_workadd.get('workadd_type')
    add_over = json_workadd.get('workadd_over')

    if add_over:
        workadd.add_state = -1
        add_to_db(workadd)
        return jsonify({'message': 'you cancel your workadd'})

    add_end = add_end if add_end else workadd.add_end
    add_start = add_start if add_start else workadd.add_start

    old_end = workadd.add_end
    old_start = workadd.add_start

    workadd.add_start = add_start
    workadd.add_end = add_end

    add_to_db(workadd)

    if workadd.add_start > workadd.add_end:
        workadd.add_end = old_end
        workadd.add_start = old_start
        delete_to_db(workadd)
        return bad_request('the start latter than end')

    if add_reason:
        workadd.add_reason = add_reason

    if add_type:
        if not WorkaddInfo.query.get(add_type):
            return bad_request('type is error')
        workadd.type = add_type

    workadd.add_state = 0

    add_to_db(workadd)
    return jsonify({'message': 'you modify your workadd'})
示例#3
0
def modify_workadd(id):
    workadd = WorkAdd.query.filter(WorkAdd.id == id).first()

    if workadd is None:
        return bad_request("the workadd isn't exit")

    json_workadd = request.json
    add_start = json_workadd.get('workadd_start')
    add_end = json_workadd.get('workadd_end')
    add_reason = json_workadd.get('workadd_reason')
    add_type = json_workadd.get('workadd_type')
    add_state = json_workadd.get('workadd_state')

    add_end = add_end if add_end else workadd.add_end
    add_start = add_start if add_start else workadd.add_start

    old_end = workadd.add_end
    old_start = workadd.add_start

    workadd.add_start = add_start
    workadd.add_end = add_end

    add_to_db(workadd)

    if workadd.add_start > workadd.add_end:
        workadd.add_end = old_end
        workadd.add_start = old_start
        delete_to_db(workadd)
        return bad_request('the start latter than end')

    if add_reason:
        workadd.add_reason = add_reason

    if add_type:
        if not WorkaddInfo.query.get(add_type):
            return bad_request('type is error')
        workadd.type = add_type

    if add_state:
        if add_state not in ['0', '-1', '1']:
            return bad_request('the add_state must in 0, -1, 1')
        else:
            workadd.add_state = add_state

    add_to_db(workadd)
    return jsonify({'message': 'you modify your workadd'})
def delete_degree_to_worker(id, department_del):
    department_id = department_del
    worker_id = id

    woker = Worker.query.filter(Worker.id == worker_id).first()

    if not woker:
        return jsonify({'message': 'the user isn\'t exit'})

    worker_degree = WorkerDegree.query.filter(
        WorkerDegree.worker_id == worker_id,
        WorkerDegree.department_id == department_id).first()

    if not worker_degree:
        return jsonify({'message': 'the user not in the department'})

    delete_to_db(worker_degree)

    return jsonify(
        {'message': 'your delete the degree to worker {}'.format(id)})
示例#5
0
def create_wordadd():
    json_workadd = request.json
    worker_id = g.current_user.id
    add_start = json_workadd.get('workadd_start')
    add_end = json_workadd.get('workadd_end')
    add_reason = json_workadd.get('workadd_reason')
    add_type = json_workadd.get('workadd_type')

    workadd = WorkAdd(worker_id=worker_id,
                      add_start=add_start,
                      add_end=add_end,
                      add_reason=add_reason,
                      apply_time=datetime.now(),
                      type=add_type)
    add_to_db(workadd)

    if workadd.add_start > workadd.add_end:
        delete_to_db(workadd)
        return bad_request('workadd start laster than end')

    if workadd.add_start <= datetime.now():
        delete_to_db(workadd)
        return bad_request('workadd start laster than now')

    if add_reason is None or add_reason == "":
        delete_to_db(workadd)
        return bad_request('workadd must have reason')

    return jsonify({'workadd_id': workadd.id}), 201