From d1b2983a9b9a0a85d3d02a082da22c871a24112b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 17 Aug 2013 18:31:26 -0700 Subject: [PATCH] Improved product UPC search so check digit is optional. --- rattail/pyramid/views/products.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/rattail/pyramid/views/products.py b/rattail/pyramid/views/products.py index 91c1f905..3e8e20d3 100644 --- a/rattail/pyramid/views/products.py +++ b/rattail/pyramid/views/products.py @@ -46,6 +46,7 @@ from rattail.exceptions import LabelPrintingError from rattail.db.model import ( Product, ProductPrice, ProductCost, ProductCode, Brand, Vendor, Department, Subdepartment, LabelProfile) +from rattail.gpc import GPC from rattail.pyramid import Session from rattail.pyramid.forms import (AutocompleteFieldRenderer, @@ -97,20 +98,22 @@ class ProductsGrid(SearchableAlchemyGridView): def filter_upc(): def filter_is(q, v): + if not v: + return q try: - v = int(v) + return q.filter(Product.upc.in_(( + GPC(v), GPC(v, calc_check_digit='upc')))) except ValueError: return q - else: - return q.filter(Product.upc == v) if v else q def filter_not(q, v): + if not v: + return q try: - v = int(v) + return q.filter(~Product.upc.in_(( + GPC(v), GPC(v, calc_check_digit='upc')))) except ValueError: return q - else: - return q.filter(Product.upc != v) if v else q return {'is': filter_is, 'nt': filter_not}