From 145e7f55298d0025f8a35d2003198f0ac9785650 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 19 Feb 2019 21:11:49 -0600 Subject: [PATCH] Allow vendor field to be dropdown, for mobile ordering/receiving based on config. useful for apps which have very few vendors --- .../static/js/tailbone.mobile.receiving.js | 7 ++++++ .../templates/mobile/ordering/create.mako | 21 +++++++++++----- .../templates/mobile/receiving/create.mako | 25 +++++++++++++------ tailbone/views/purchasing/ordering.py | 15 ++++++++++- tailbone/views/purchasing/receiving.py | 17 +++++++++++-- 5 files changed, 68 insertions(+), 17 deletions(-) diff --git a/tailbone/static/js/tailbone.mobile.receiving.js b/tailbone/static/js/tailbone.mobile.receiving.js index c82a7924..d46740ac 100644 --- a/tailbone/static/js/tailbone.mobile.receiving.js +++ b/tailbone/static/js/tailbone.mobile.receiving.js @@ -15,6 +15,13 @@ $(document).on('autocompleteitemselected', 'form[name="new-receiving-batch"] .ve $(document).on('autocompleteitemcleared', 'form[name="new-receiving-batch"] .vendor', function(event) { $('#new-receiving-types').hide(); }); +$(document).on('change', 'form[name="new-receiving-batch"] select[name="vendor"]', function(event) { + if ($(this).val()) { + $('#new-receiving-types').show(); + } else { + $('#new-receiving-types').hide(); + } +}); // submit new receiving batch form when user clicks "Receive" type button diff --git a/tailbone/templates/mobile/ordering/create.mako b/tailbone/templates/mobile/ordering/create.mako index 68f11737..ae292269 100644 --- a/tailbone/templates/mobile/ordering/create.mako +++ b/tailbone/templates/mobile/ordering/create.mako @@ -9,12 +9,21 @@ ${h.form(request.current_route_url(), class_='ui-filterable', name='new-purchasi ${h.csrf_token(request)}
-
- ${h.hidden('vendor')} - ${h.text('new-purchasing-batch-vendor-text', placeholder="Vendor name", autocomplete='off', data_type='search')} -
    - -
    + % if vendor_use_autocomplete: +
    + ${h.hidden('vendor')} + ${h.text('new-purchasing-batch-vendor-text', placeholder="Vendor name", autocomplete='off', data_type='search')} +
      + +
      + % else: +
      + +
      + ${h.select('vendor', None, vendor_options)} +
      +
      + % endif

      diff --git a/tailbone/templates/mobile/receiving/create.mako b/tailbone/templates/mobile/receiving/create.mako index 668ab69f..97cb132d 100644 --- a/tailbone/templates/mobile/receiving/create.mako +++ b/tailbone/templates/mobile/receiving/create.mako @@ -10,14 +10,23 @@ ${h.csrf_token(request)} % if phase == 1: -
      -
      - ${h.hidden('vendor')} - ${h.text('new-receiving-batch-vendor-text', placeholder="Vendor name", autocomplete='off', **{'data-type': 'search'})} -
        - -
        -
        + % if vendor_use_autocomplete: +
        +
        + ${h.hidden('vendor')} + ${h.text('new-receiving-batch-vendor-text', placeholder="Vendor name", autocomplete='off', **{'data-type': 'search'})} +
          + +
          +
          + % else: +
          + +
          + ${h.select('vendor', None, vendor_options)} +
          +
          + % endif
          diff --git a/tailbone/views/purchasing/ordering.py b/tailbone/views/purchasing/ordering.py index 87a61ca5..06d7eb6b 100644 --- a/tailbone/views/purchasing/ordering.py +++ b/tailbone/views/purchasing/ordering.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2017 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -36,6 +36,8 @@ from rattail.db import model, api from rattail.core import Object from rattail.time import localtime +from webhelpers2.html import tags + from tailbone.views.purchasing import PurchasingBatchView @@ -317,6 +319,17 @@ class OrderingBatchView(PurchasingBatchView): data['index_title'] = self.get_index_title() data['index_url'] = self.get_index_url(mobile=True) data['mode_title'] = self.enum.PURCHASE_BATCH_MODE[mode].capitalize() + + data['vendor_use_autocomplete'] = self.rattail_config.getbool( + 'rattail', 'vendor.use_autocomplete', default=True) + if not data['vendor_use_autocomplete']: + vendors = self.Session.query(model.Vendor)\ + .order_by(model.Vendor.name) + options = [(tags.Option(vendor.name, vendor.uuid)) + for vendor in vendors] + options.insert(0, tags.Option("(please choose)", '')) + data['vendor_options'] = options + return self.render_to_response('create', data, mobile=True) def configure_mobile_row_form(self, f): diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 2c7969bc..b4c7cc2a 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2018 Lance Edgar +# Copyright © 2010-2019 Lance Edgar # # This file is part of Rattail. # @@ -677,10 +677,23 @@ class ReceivingBatchView(PurchasingBatchView): data['dform'] = form.make_deform_form() data['mode_title'] = self.enum.PURCHASE_BATCH_MODE[mode].capitalize() data['phase'] = phase - if phase == 2: + + if phase == 1: + data['vendor_use_autocomplete'] = self.rattail_config.getbool( + 'rattail', 'vendor.use_autocomplete', default=True) + if not data['vendor_use_autocomplete']: + vendors = self.Session.query(model.Vendor)\ + .order_by(model.Vendor.name) + options = [(tags.Option(vendor.name, vendor.uuid)) + for vendor in vendors] + options.insert(0, tags.Option("(please choose)", '')) + data['vendor_options'] = options + + elif phase == 2: purchases = self.eligible_purchases(vendor.uuid, mode=mode) data['purchases'] = [(p['key'], p['display']) for p in purchases['purchases']] data['purchase_order_fieldname'] = self.purchase_order_fieldname + return self.render_to_response('create', data, mobile=True) def make_mobile_receiving_from_po_schema(self):