Make product UPC search view strip non-digit chars from input.

This is to accomodate the apparently frequent use case of copy/paste which
includes the check digit as a "-X" type suffix.
This commit is contained in:
Lance Edgar 2014-12-18 15:43:49 -06:00
parent d5a8d19165
commit 2a04caaf99

View file

@ -20,7 +20,6 @@
# along with Rattail. If not, see <http://www.gnu.org/licenses/>. # along with Rattail. If not, see <http://www.gnu.org/licenses/>.
# #
################################################################################ ################################################################################
""" """
Product Views Product Views
""" """
@ -28,6 +27,7 @@ Product Views
from __future__ import unicode_literals from __future__ import unicode_literals
import os import os
import re
from sqlalchemy import and_ from sqlalchemy import and_
from sqlalchemy.orm import joinedload, aliased from sqlalchemy.orm import joinedload, aliased
@ -295,9 +295,9 @@ def products_search(request):
Eventually this should be more generic, or at least offer more fields for Eventually this should be more generic, or at least offer more fields for
search. For now it operates only on the ``Product.upc`` field. search. For now it operates only on the ``Product.upc`` field.
""" """
product = None product = None
upc = request.GET.get('upc') upc = request.GET.get('upc', '').strip()
upc = re.sub(r'\D', '', upc)
if upc: if upc:
product = get_product_by_upc(Session, upc) product = get_product_by_upc(Session, upc)
if not product: if not product: