Add custom Person views, to expose corepos_customer_id field

This commit is contained in:
Lance Edgar 2020-03-16 19:46:53 -05:00
parent 10ba1f27a7
commit 79c6829f3c

View file

@ -0,0 +1,61 @@
# -*- coding: utf-8; -*-
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2020 Lance Edgar
#
# This file is part of Rattail.
#
# Rattail is free software: you can redistribute it and/or modify it under the
# terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or (at your option) any later
# version.
#
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# Rattail. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
Person views
"""
from tailbone.views import people as base
class PersonView(base.PeopleView):
"""
Expose some extra fields etc. per CORE-POS integration.
Please note that this does include a bit of "business logic" which assumes
that you keep CORE and Rattail in sync! Use at your own risk.
"""
labels = {
'corepos_customer_id': "CORE-POS Customer ID",
}
def query(self, session):
query = super(PersonView, self).query(session)
model = self.rattail_config.get_model()
query = query.outerjoin(model.CorePerson)
return query
def configure_grid(self, g):
super(PersonView, self).configure_grid(g)
model = self.rattail_config.get_model()
g.append('corepos_customer_id')
g.set_sorter('corepos_customer_id', model.CorePerson.corepos_customer_id)
g.set_filter('corepos_customer_id', model.CorePerson.corepos_customer_id)
g.set_label('corepos_customer_id', "CORE ID")
g.filters['corepos_customer_id'].label = "CORE-POS Customer ID"
def configure_form(self, f):
super(PersonView, self).configure_form(f)
f.append('corepos_customer_id')