diff --git a/tailbone/views/batches/rows.py b/tailbone/views/batches/rows.py index 32127212..071790e4 100644 --- a/tailbone/views/batches/rows.py +++ b/tailbone/views/batches/rows.py @@ -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))