From 5b48c44891dd5f9f6f1a5785d374caee56238dfe Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 4 Dec 2020 15:39:00 -0600 Subject: [PATCH] Add email filters for CustData grid; allow downloading results --- tailbone_corepos/views/corepos/customers.py | 39 +++++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/tailbone_corepos/views/corepos/customers.py b/tailbone_corepos/views/corepos/customers.py index 713535d..297b3b2 100644 --- a/tailbone_corepos/views/corepos/customers.py +++ b/tailbone_corepos/views/corepos/customers.py @@ -42,6 +42,7 @@ class CustomerView(CoreOfficeMasterView): model_title_plural = "CORE-POS Customers (Legacy)" url_prefix = '/core-pos/customers' route_prefix = 'corepos.customers' + results_downloadable = True labels = { 'id': "ID", @@ -67,6 +68,14 @@ class CustomerView(CoreOfficeMasterView): 'purchases', ] + def query(self, session): + query = super(CustomerView, self).query(session) + + query = query.outerjoin(corepos.MemberInfo, + corepos.MemberInfo.card_number == corepos.CustData.card_number) + + return query + def configure_grid(self, g): super(CustomerView, self).configure_grid(g) @@ -79,9 +88,12 @@ class CustomerView(CoreOfficeMasterView): g.filters['last_name'].default_active = True g.filters['last_name'].default_verb = 'contains' - g.set_joiner('member_type', lambda q: q.outerjoin(corepos.MemberType)) - g.set_sorter('member_type', corepos.MemberType.description) - g.set_filter('member_type', corepos.MemberType.description) + g.set_joiner('member_type_description', lambda q: q.outerjoin(corepos.MemberType)) + g.set_sorter('member_type_description', corepos.MemberType.description) + g.set_filter('member_type_description', corepos.MemberType.description) + + g.set_filter('member_info_email', corepos.MemberInfo.email) + g.set_filter('member_info_email2', corepos.MemberInfo.email2) g.set_type('charge_limit', 'currency') g.set_type('balance', 'currency') @@ -128,6 +140,27 @@ class CustomerView(CoreOfficeMasterView): customer.card_number, office_url=office_url) + def download_results_fields_available(self, **kwargs): + fields = super(CustomerView, self).download_results_fields_available(**kwargs) + + fields.extend([ + 'email', + 'email2', + ]) + + return fields + + def download_results_normalize(self, custdata, fields, **kwargs): + data = super(CustomerView, self).download_results_normalize(custdata, fields, **kwargs) + + # import ipdb; ipdb.set_trace() + + for field in ('email', 'email2'): + if field in fields: + data[field] = getattr(custdata.member_info, field) if custdata.member_info else None + + return data + def includeme(config): CustomerView.defaults(config)