fix employee views

This commit is contained in:
Lance Edgar 2012-08-10 14:18:28 -07:00
parent 4051d125c2
commit 96046d9089

View file

@ -45,11 +45,19 @@ class EmployeesGrid(SearchableAlchemyGridView):
renderer = '/employees/index.mako' renderer = '/employees/index.mako'
sort = 'first_name' sort = 'first_name'
def join_map(self):
return {
'phone':
lambda q: q.outerjoin(rattail.EmployeePhoneNumber, and_(
rattail.EmployeePhoneNumber.parent_uuid == rattail.Employee.uuid,
rattail.EmployeePhoneNumber.preference == 1)),
}
def filter_map(self): def filter_map(self):
return self.make_filter_map( return self.make_filter_map(
first_name=grids.search.filter_ilike(edbob.Person.first_name), first_name=grids.search.filter_ilike(edbob.Person.first_name),
last_name=grids.search.filter_ilike(edbob.Person.last_name), last_name=grids.search.filter_ilike(edbob.Person.last_name),
phone=grids.search.filter_ilike(edbob.PersonPhone.number)) phone=grids.search.filter_ilike(rattail.EmployeePhoneNumber.number))
def filter_config(self): def filter_config(self):
return self.make_filter_config( return self.make_filter_config(
@ -63,14 +71,11 @@ class EmployeesGrid(SearchableAlchemyGridView):
return self.make_sort_map( return self.make_sort_map(
first_name=grids.util.sorter(edbob.Person.first_name), first_name=grids.util.sorter(edbob.Person.first_name),
last_name=grids.util.sorter(edbob.Person.last_name), last_name=grids.util.sorter(edbob.Person.last_name),
phone=grids.util.sorter(edbob.PersonPhone.number)) phone=grids.util.sorter(rattail.EmployeePhoneNumber.number))
def query(self): def query(self):
q = self.make_query() q = self.make_query()
q = q.join(edbob.Person) q = q.join(edbob.Person)
q = q.outerjoin(edbob.PersonPhone, and_(
edbob.PersonPhone.parent_uuid == rattail.Employee.person_uuid,
edbob.PersonPhone.preference == 1))
if not self.request.has_perm('employees.edit'): if not self.request.has_perm('employees.edit'):
q = q.filter(rattail.Employee.status == rattail.EMPLOYEE_STATUS_CURRENT) q = q.filter(rattail.Employee.status == rattail.EMPLOYEE_STATUS_CURRENT)
return q return q