Add master view for CustomerShopper
This commit is contained in:
parent
5f4d393db3
commit
92538b87ad
|
@ -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',
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue