def _get_reimbursements_needing_attention(employee):
    employee.reimbursements_needing_attention = ReimbursementDao.get_reimbursements_awaiting_approval(
        employee.id, 7)
    employee.reimbursements_needing_attention += ReimbursementDao.get_reimbursements_awaiting_approval(
        employee.id, 5)
    employee.reimbursements_needing_attention += ReimbursementDao.get_reimbursements_awaiting_approval(
        employee.id, 4)
    if employee.department.head == employee.id:
        department_employees = EmployeeDao.get_employees_by_department(
            employee.department.id)
        for emp in department_employees:
            employee.reimbursements_needing_attention += \
                ReimbursementDao.get_reimbursements_awaiting_approval(emp.id, 2)
    supervised_employees = EmployeeDao.get_supervised_employees(employee.id)
    for emp in supervised_employees:
        employee.reimbursements_needing_attention += \
            ReimbursementDao.get_reimbursements_awaiting_approval(emp.id, 1)
    if employee.role.id == 4:
        employee.reimbursements_needing_attention += \
            ReimbursementDao.get_all_reimbursements_for_benco()
    def get_all_reimbursements_for_benco():
        sql = "Select * from reimbursements where status_id = 3"
        cursor = connection.cursor()
        cursor.execute(sql)
        records = cursor.fetchall()
        reimbursements = []

        for record in records:
            reimbursement = Reimbursement(id=record[0],
                                          date_submitted=record[3],
                                          amount=record[5],
                                          message=record[6])
            reimbursement.course = CourseDao.get_course(record[4])
            reimbursement.employee = EmployeeDao.get_employee(record[1])
            reimbursement.status = ReimbursementStatusDao.get_status(record[2])
            reimbursements.append(reimbursement)

        return reimbursements
    def get_reimbursements_awaiting_approval(employee_id, status_id):
        sql = "Select * from reimbursements where employee_id=%s and status_id = %s"
        cursor = connection.cursor()
        cursor.execute(sql, [employee_id, status_id])
        records = cursor.fetchall()
        reimbursements = []

        for record in records:
            reimbursement = Reimbursement(id=record[0],
                                          date_submitted=record[3],
                                          amount=record[5],
                                          message=record[6])
            reimbursement.course = CourseDao.get_course(record[4])
            reimbursement.employee = EmployeeDao.get_employee(record[1])
            reimbursement.status = ReimbursementStatusDao.get_status(record[2])
            reimbursements.append(reimbursement)

        return reimbursements
 def login(login_id):
     employee = EmployeeDao.login(login_id)
     _get_reimbursements_needing_attention(employee)
     employee.total_reimbursements_this_year = ReimbursementDao.get_reimbursements_total_for(
         employee.id)
     return employee
 def test_login(self):
     employee = EmployeeDao.login('100007')
     assert employee
 def test_get_department_employees(self):
     assert EmployeeDao.get_employees_by_department(1)
 def test_get_supervised_employees(self):
     assert EmployeeDao.get_supervised_employees(1)
 def test_get_employee(self):
     assert EmployeeDao.get_employee(1)