Beispiel #1
0
def create_new_employee():
    if request.method == 'POST':
        name = request.form['name']
        gender = request.form['gender']
        email = request.form['email']
        kra_pin = request.form['kra']
        basic_salary = request.form['basic']
        benefits = request.form['benefits']

        if EmployeesModel.check_kra_pin(kra_pin) or EmployeesModel.check_email(
                email):
            flash("Email/Kra already exists")
            return redirect(url_for('home'))

        emp = EmployeesModel(name=name,
                             gender=gender,
                             email=email,
                             kra_pin=kra_pin,
                             basic_salary=basic_salary,
                             benefits=benefits)
        emp.insert_record()

        return redirect(url_for('home'))
Beispiel #2
0
def edit_employee(id):
    name = request.form['name']
    gender = request.form['gender']
    email = request.form['email']
    kra_pin = request.form['kra']
    basic_salary = request.form['basic']
    benefits = request.form['benefits']

    current_user = EmployeesModel.fetch_by_id(id)
    # use and to capture this error
    if EmployeesModel.check_kra_pin(kra_pin) and kra_pin != current_user.kra_pin or \
            EmployeesModel.check_email(email) and email != current_user.email:
        flash("Kra/email already exists")
        return redirect(url_for('home'))

    EmployeesModel.update_by_id(id=id,
                                name=name,
                                gender=gender,
                                email=email,
                                kra_pin=kra_pin,
                                basic_salary=basic_salary,
                                benefits=benefits)
    return redirect(url_for('home'))