From 96046d908927aaf25b782b4072ace6114c7b4413 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 10 Aug 2012 14:18:28 -0700 Subject: [PATCH] fix employee views --- rattail/pyramid/views/employees.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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