Add "quick lookup" for mobile Products page
only if enabled, otherwise just shows the normal grid
This commit is contained in:
parent
21740ea2fd
commit
950af8b5e0
7 changed files with 68 additions and 18 deletions
|
@ -152,7 +152,7 @@ class BatchMasterView(MasterView):
|
|||
if self.mobile_rows_creatable:
|
||||
kwargs.setdefault('add_item_title', "Add Item")
|
||||
if self.mobile_rows_quickable:
|
||||
kwargs.setdefault('quick_row_entry_placeholder', "Enter {}".format(
|
||||
kwargs.setdefault('quick_entry_placeholder', "Enter {}".format(
|
||||
self.rattail_config.product_key_title()))
|
||||
if kwargs['execute_enabled']:
|
||||
url = self.get_action_url('execute', batch)
|
||||
|
|
|
@ -1151,7 +1151,7 @@ class MasterView(View):
|
|||
|
||||
def make_quick_row_form_schema(self, mobile=False):
|
||||
schema = colander.MappingSchema()
|
||||
schema.add(colander.SchemaNode(colander.String(), name='quick_row_entry'))
|
||||
schema.add(colander.SchemaNode(colander.String(), name='quick_entry'))
|
||||
return schema
|
||||
|
||||
def make_quick_row_form_kwargs(self, **kwargs):
|
||||
|
@ -2572,7 +2572,7 @@ class MasterView(View):
|
|||
row = self.save_quick_row_form(form)
|
||||
if not row:
|
||||
self.request.session.flash("Could not locate/create row for entry: "
|
||||
"{}".format(form.validated['quick_row_entry']),
|
||||
"{}".format(form.validated['quick_entry']),
|
||||
'error')
|
||||
return self.redirect(parent_url)
|
||||
return self.redirect_after_quick_row(row, mobile=True)
|
||||
|
|
|
@ -725,6 +725,35 @@ class ProductsView(MasterView):
|
|||
'instance_title': self.get_instance_title(instance),
|
||||
'form': form})
|
||||
|
||||
def mobile_index(self):
|
||||
"""
|
||||
Mobile "home" page for products
|
||||
"""
|
||||
self.mobile = True
|
||||
context = {
|
||||
'quick_lookup': False,
|
||||
'placeholder': "Enter {}".format(self.rattail_config.product_key_title()),
|
||||
'quick_lookup_keyboard_wedge': True,
|
||||
}
|
||||
if self.rattail_config.getbool('rattail', 'products.mobile.quick_lookup', default=False):
|
||||
context['quick_lookup'] = True
|
||||
else:
|
||||
self.listing = True
|
||||
grid = self.make_mobile_grid()
|
||||
context['grid'] = grid
|
||||
return self.render_to_response('index', context, mobile=True)
|
||||
|
||||
def mobile_quick_lookup(self):
|
||||
entry = self.request.POST['quick_entry']
|
||||
provided = GPC(entry, calc_check_digit=False)
|
||||
product = api.get_product_by_upc(self.Session(), provided)
|
||||
if not product:
|
||||
checked = GPC(entry, calc_check_digit='upc')
|
||||
product = api.get_product_by_upc(self.Session(), checked)
|
||||
if not product:
|
||||
raise self.notfound()
|
||||
return self.redirect(self.get_action_url('view', product, mobile=True))
|
||||
|
||||
def get_version_child_classes(self):
|
||||
return [
|
||||
(model.ProductCode, 'product_uuid'),
|
||||
|
@ -938,6 +967,10 @@ class ProductsView(MasterView):
|
|||
config.add_route('products.image', '/products/{uuid}/image')
|
||||
config.add_view(cls, attr='image', route_name='products.image')
|
||||
|
||||
# mobile quick lookup
|
||||
config.add_route('mobile.products.quick_lookup', '/mobile/products/quick-lookup')
|
||||
config.add_view(cls, attr='mobile_quick_lookup', route_name='mobile.products.quick_lookup')
|
||||
|
||||
|
||||
class ProductsAutocomplete(AutocompleteView):
|
||||
"""
|
||||
|
|
|
@ -991,7 +991,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
|||
|
||||
def save_quick_row_form(self, form):
|
||||
batch = self.get_instance()
|
||||
entry = form.validated['quick_row_entry']
|
||||
entry = form.validated['quick_entry']
|
||||
|
||||
# maybe try to locate existing row first
|
||||
rows = self.quick_locate_rows(batch, entry)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue