From 92538b87ad2b51f6e9de0fbb2cbecbf41a99296e Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 11 Jun 2023 20:52:24 -0500 Subject: [PATCH] Add master view for CustomerShopper --- tailbone/menus.py | 5 +++ tailbone/views/customers.py | 61 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/tailbone/menus.py b/tailbone/menus.py index 8aebf043..8f98b91b 100644 --- a/tailbone/menus.py +++ b/tailbone/menus.py @@ -343,6 +343,11 @@ class MenuHandler(GenericHandler): 'route': 'customers', 'perm': 'customers.list', }, + { + 'title': "Customer Shoppers", + 'route': 'customer_shoppers', + 'perm': 'customer_shoppers.list', + }, { 'title': "Customer Groups", 'route': 'customergroups', diff --git a/tailbone/views/customers.py b/tailbone/views/customers.py index af90f0f5..2f00bc2e 100644 --- a/tailbone/views/customers.py +++ b/tailbone/views/customers.py @@ -675,6 +675,63 @@ class CustomerView(MasterView): permission='{}.detach_person'.format(permission_prefix)) +class CustomerShopperView(MasterView): + """ + Master view for the CustomerShopper class. + """ + model_class = model.CustomerShopper + route_prefix = 'customer_shoppers' + url_prefix = '/customer-shoppers' + + grid_columns = [ + 'customer_key', + 'customer', + 'shopper_number', + 'person', + 'active', + ] + + form_fields = [ + 'customer', + 'shopper_number', + 'person', + 'active', + ] + + def query(self, session): + query = super().query(session) + model = self.model + return query.join(model.Customer) + + def configure_grid(self, g): + super().configure_grid(g) + app = self.get_rattail_app() + model = self.model + + # customer_key + key = app.get_customer_key_field() + label = app.get_customer_key_label() + g.set_label('customer_key', label) + g.set_renderer('customer_key', + lambda shopper, field: getattr(shopper.customer, key)) + g.set_sorter('customer_key', getattr(model.Customer, key)) + g.set_filter('customer_key', getattr(model.Customer, key), + label=f"Customer {label}", + default_active=True, + default_verb='equal') + + # customer (name) + g.set_sorter('customer', model.Customer.name) + g.set_filter('customer', model.Customer.name, + label="Customer Name") + + def configure_form(self, f): + super().configure_form(f) + + f.set_renderer('customer', self.render_customer) + f.set_renderer('person', self.render_person) + + class PendingCustomerView(MasterView): """ Master view for the Pending Customer class. @@ -841,6 +898,10 @@ def defaults(config, **kwargs): base['CustomerView']) CustomerView.defaults(config) + CustomerShopperView = kwargs.get('CustomerShopperView', + base['CustomerShopperView']) + CustomerShopperView.defaults(config) + PendingCustomerView = kwargs.get('PendingCustomerView', base['PendingCustomerView']) PendingCustomerView.defaults(config)