Improved product UPC search so check digit is optional.

This commit is contained in:
Lance Edgar 2013-08-17 18:31:26 -07:00
parent 1ade594046
commit d1b2983a9b

View file

@ -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}