diff --git a/rattail/pyramid/views/employees.py b/rattail/pyramid/views/employees.py index 494dae8d..9be23509 100644 --- a/rattail/pyramid/views/employees.py +++ b/rattail/pyramid/views/employees.py @@ -45,11 +45,19 @@ class EmployeesGrid(SearchableAlchemyGridView): renderer = '/employees/index.mako' 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): return self.make_filter_map( first_name=grids.search.filter_ilike(edbob.Person.first_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): return self.make_filter_config( @@ -63,14 +71,11 @@ class EmployeesGrid(SearchableAlchemyGridView): return self.make_sort_map( first_name=grids.util.sorter(edbob.Person.first_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): q = self.make_query() 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'): q = q.filter(rattail.Employee.status == rattail.EMPLOYEE_STATUS_CURRENT) return q