Add filter support for mobile row grid; plus mark receiving as complete
This commit is contained in:
parent
f47157102c
commit
98ff71a2dd
7 changed files with 96 additions and 33 deletions
|
@ -96,6 +96,7 @@ class MasterView(View):
|
|||
rows_bulk_deletable = False
|
||||
rows_default_pagesize = 20
|
||||
|
||||
mobile_rows_filterable = False
|
||||
mobile_rows_viewable = False
|
||||
|
||||
@property
|
||||
|
@ -206,11 +207,32 @@ class MasterView(View):
|
|||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def make_mobile_row_grid_kwargs(self, **kwargs):
|
||||
"""
|
||||
Must return a dictionary of kwargs to be passed to the factory when
|
||||
creating new mobile *row* grid instances.
|
||||
"""
|
||||
defaults = {
|
||||
'route_prefix': self.get_route_prefix(),
|
||||
'pageable': self.pageable,
|
||||
'sortable': False,
|
||||
'filterable': self.mobile_rows_filterable,
|
||||
}
|
||||
if self.mobile_rows_filterable:
|
||||
defaults['filters'] = self.make_mobile_row_filters()
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def make_mobile_filters(self):
|
||||
"""
|
||||
Returns a set of filters for the mobile grid, if applicable.
|
||||
"""
|
||||
|
||||
def make_mobile_row_filters(self):
|
||||
"""
|
||||
Returns a set of filters for the mobile row grid, if applicable.
|
||||
"""
|
||||
|
||||
def preconfigure_mobile_grid(self, grid):
|
||||
"""
|
||||
Optionally perform pre-configuration for the mobile grid, to establish
|
||||
|
@ -588,14 +610,6 @@ class MasterView(View):
|
|||
def get_mobile_row_data(self, parent):
|
||||
return self.get_row_data(parent)
|
||||
|
||||
def make_mobile_row_grid_kwargs(self, **kwargs):
|
||||
defaults = {
|
||||
'pageable': True,
|
||||
'sortable': True,
|
||||
}
|
||||
defaults.update(kwargs)
|
||||
return defaults
|
||||
|
||||
def make_mobile_row_grid(self, **kwargs):
|
||||
"""
|
||||
Make a new (configured) rows grid instance for mobile.
|
||||
|
@ -607,7 +621,7 @@ class MasterView(View):
|
|||
kwargs.setdefault('request', self.request)
|
||||
kwargs.setdefault('model_class', self.model_row_class)
|
||||
kwargs = self.make_mobile_row_grid_kwargs(**kwargs)
|
||||
factory = self.get_grid_factory()
|
||||
factory = self.get_mobile_grid_factory()
|
||||
grid = factory(**kwargs)
|
||||
self.configure_mobile_row_grid(grid)
|
||||
grid.load_settings()
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue