From 79c6829f3c02ffa50fff71c7527b69a9465fb5c4 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Mon, 16 Mar 2020 19:46:53 -0500 Subject: [PATCH] Add custom Person views, to expose `corepos_customer_id` field --- tailbone_corepos/views/people.py | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tailbone_corepos/views/people.py diff --git a/tailbone_corepos/views/people.py b/tailbone_corepos/views/people.py new file mode 100644 index 0000000..8212ac5 --- /dev/null +++ b/tailbone_corepos/views/people.py @@ -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 . +# +################################################################################ +""" +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')