Add filter support for mobile row grid; plus mark receiving as complete

This commit is contained in:
Lance Edgar 2017-07-10 22:10:27 -05:00
parent f47157102c
commit 98ff71a2dd
7 changed files with 96 additions and 33 deletions

View file

@ -69,6 +69,33 @@ class MobileBatchStatusFilter(grids.filters.MobileFilter):
yield value, prettify(value)
class MobileItemStatusFilter(grids.filters.MobileFilter):
value_choices = ['incomplete', 'damaged', 'expired', 'all']
def filter_equal(self, query, value):
# TODO: is this accurate (enough) ?
if value == 'incomplete':
return query.filter(model.PurchaseBatchRow.status_code != model.PurchaseBatchRow.STATUS_OK)
if value == 'damaged':
return query.filter(sa.or_(
model.PurchaseBatchRow.cases_damaged != 0,
model.PurchaseBatchRow.units_damaged != 0))
if value == 'expired':
return query.filter(sa.or_(
model.PurchaseBatchRow.cases_expired != 0,
model.PurchaseBatchRow.units_expired != 0))
return query
def iter_choices(self):
for value in self.value_choices:
yield value, prettify(value)
class ReceivingBatchView(PurchasingBatchView):
"""
Master view for receiving batches
@ -82,6 +109,7 @@ class ReceivingBatchView(PurchasingBatchView):
supports_mobile = True
mobile_creatable = True
mobile_filterable = True
mobile_rows_filterable = True
mobile_rows_viewable = True
@property
@ -96,6 +124,14 @@ class ReceivingBatchView(PurchasingBatchView):
filters['status'] = MobileBatchStatusFilter('status', default_value='pending')
return filters
def make_mobile_row_filters(self):
"""
Returns a set of filters for the mobile row grid.
"""
filters = grids.filters.GridFilterSet()
filters['status'] = MobileItemStatusFilter('status', default_value='incomplete')
return filters
def mobile_create(self):
"""
Mobile view for creating a new receiving batch
@ -289,11 +325,17 @@ class ReceivingBatchView(PurchasingBatchView):
row.credits.append(credit)
return credit
def mobile_mark_complete(self):
batch = self.get_instance()
batch.complete = True
return self.redirect(self.request.route_url('mobile.{}'.format(self.get_route_prefix())))
@classmethod
def defaults(cls, config):
route_prefix = cls.get_route_prefix()
url_prefix = cls.get_url_prefix()
model_key = cls.get_model_key()
permission_prefix = cls.get_permission_prefix()
row_permission_prefix = cls.get_row_permission_prefix()
# mobile lookup
@ -301,6 +343,11 @@ class ReceivingBatchView(PurchasingBatchView):
config.add_view(cls, attr='mobile_lookup', route_name='mobile.{}.lookup'.format(route_prefix),
renderer='json', permission='{}.view'.format(row_permission_prefix))
# mobile mark complete
config.add_route('mobile.{}.mark_complete'.format(route_prefix), '/mobile{}/{{{}}}/mark-complete'.format(url_prefix, model_key))
config.add_view(cls, attr='mobile_mark_complete', route_name='mobile.{}.mark_complete'.format(route_prefix),
permission='{}.edit'.format(permission_prefix))
cls._purchasing_defaults(config)
cls._batch_defaults(config)
cls._defaults(config)