Improve UPC search for rows within batches.
As with the products page, now this search works with or without the check digit.
This commit is contained in:
parent
7d42950527
commit
e47477f0c4
|
@ -33,7 +33,9 @@ from tailbone.forms import GPCFieldRenderer
|
|||
from tailbone.grids.search import BooleanSearchFilter
|
||||
from tailbone.db import Session
|
||||
|
||||
from rattail.db import model
|
||||
from rattail.db.model import Batch, LabelProfile
|
||||
from rattail.gpc import GPC
|
||||
|
||||
|
||||
def field_with_renderer(field, column):
|
||||
|
@ -62,9 +64,34 @@ def BatchRowsGrid(request):
|
|||
sort = 'ordinal'
|
||||
|
||||
def filter_map(self):
|
||||
|
||||
# TODO: This code is copied from `tailbone.views.products`, which
|
||||
# means we probably should refactor...
|
||||
|
||||
def filter_F01_is(q, v):
|
||||
if not v:
|
||||
return q
|
||||
try:
|
||||
return q.filter(model.Product.upc.in_((
|
||||
GPC(v), GPC(v, calc_check_digit='upc'))))
|
||||
except ValueError:
|
||||
return q
|
||||
|
||||
def filter_F01_not(q, v):
|
||||
if not v:
|
||||
return q
|
||||
try:
|
||||
return q.filter(~model.Product.upc.in_((
|
||||
GPC(v), GPC(v, calc_check_digit='upc'))))
|
||||
except ValueError:
|
||||
return q
|
||||
|
||||
fmap = self.make_filter_map()
|
||||
for column in batch.columns:
|
||||
if column.visible:
|
||||
if column.sil_name == 'F01':
|
||||
fmap[column.name] = {'is': filter_F01_is,
|
||||
'nt': filter_F01_not}
|
||||
elif column.visible:
|
||||
if column.data_type.startswith('CHAR'):
|
||||
fmap[column.name] = self.filter_ilike(
|
||||
getattr(batch.rowclass, column.name))
|
||||
|
|
Loading…
Reference in a new issue