Add filter support for mobile row grid; plus mark receiving as complete
This commit is contained in:
parent
f47157102c
commit
98ff71a2dd
|
@ -47,3 +47,8 @@ class MobileGrid(AlchemyGrid):
|
||||||
context['request'] = self.request
|
context['request'] = self.request
|
||||||
context['grid'] = self
|
context['grid'] = self
|
||||||
return render(template, context)
|
return render(template, context)
|
||||||
|
|
||||||
|
def render_complete(self, template='/mobile/grid_complete.mako', **kwargs):
|
||||||
|
context = kwargs
|
||||||
|
context['grid'] = self
|
||||||
|
return render(template, context)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
## -*- coding: utf-8; -*-
|
## -*- coding: utf-8; -*-
|
||||||
<div class="simple-filter">
|
<div class="simple-filter">
|
||||||
${h.form(request.current_route_url(), method='get')}
|
${h.form(request.current_route_url(_query=None), method='get')}
|
||||||
${h.csrf_token(request)}
|
|
||||||
|
|
||||||
% for filtr in grid.iter_filters():
|
% for filtr in grid.iter_filters():
|
||||||
${h.hidden('{}.verb'.format(filtr.key), value=filtr.verb)}
|
${h.hidden('{}.verb'.format(filtr.key), value=filtr.verb)}
|
||||||
|
|
11
tailbone/templates/mobile/grid_complete.mako
Normal file
11
tailbone/templates/mobile/grid_complete.mako
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
## -*- coding: utf-8; -*-
|
||||||
|
|
||||||
|
% if grid.filterable:
|
||||||
|
${grid.render_filters()|n}
|
||||||
|
% endif
|
||||||
|
|
||||||
|
<ul data-role="listview">
|
||||||
|
% for obj in grid.iter_rows():
|
||||||
|
<li>${grid.listitem.render_readonly()}</li>
|
||||||
|
% endfor
|
||||||
|
</ul>
|
|
@ -9,15 +9,7 @@
|
||||||
|
|
||||||
<%def name="title()">${model_title_plural}</%def>
|
<%def name="title()">${model_title_plural}</%def>
|
||||||
|
|
||||||
% if grid.filterable:
|
${grid.render_complete()|n}
|
||||||
${grid.render_filters()|n}
|
|
||||||
% endif
|
|
||||||
|
|
||||||
<ul data-role="listview">
|
|
||||||
% for obj in grid.iter_rows():
|
|
||||||
<li>${grid.listitem.render_readonly()}</li>
|
|
||||||
% endfor
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
## <table data-role="table" class="ui-responsive table-stroke">
|
## <table data-role="table" class="ui-responsive table-stroke">
|
||||||
## <thead>
|
## <thead>
|
||||||
|
|
|
@ -9,17 +9,12 @@ ${form.render()|n}
|
||||||
${h.text('upc-search', class_='receiving-upc-search', placeholder="Enter UPC", autocomplete='off', **{'data-type': 'search', 'data-url': url('mobile.receiving.lookup', uuid=batch.uuid)})}
|
${h.text('upc-search', class_='receiving-upc-search', placeholder="Enter UPC", autocomplete='off', **{'data-type': 'search', 'data-url': url('mobile.receiving.lookup', uuid=batch.uuid)})}
|
||||||
<br />
|
<br />
|
||||||
|
|
||||||
<fieldset data-role="controlgroup" data-type="horizontal">
|
${grid.render_complete()|n}
|
||||||
## ${h.radio('receiving-row-filter', value='missing', label="Missing", disabled='disabled')}
|
|
||||||
${h.radio('receiving-row-filter', value='incomplete', label="Incomplete", disabled='disabled')}
|
|
||||||
${h.radio('receiving-row-filter', value='damaged', label="Damaged", disabled='disabled')}
|
|
||||||
${h.radio('receiving-row-filter', value='expired', label="Expired", disabled='disabled')}
|
|
||||||
${h.radio('receiving-row-filter', value='all', label="All", checked=True)}
|
|
||||||
</fieldset>
|
|
||||||
<br /><br />
|
|
||||||
|
|
||||||
<ul data-role="listview">
|
% if not instance.executed and not instance.complete:
|
||||||
% for obj in grid.iter_rows():
|
<br /><br />
|
||||||
<li>${grid.listitem.render_readonly()}</li>
|
${h.form(request.route_url('mobile.receiving.mark_complete', uuid=instance.uuid))}
|
||||||
% endfor
|
${h.csrf_token(request)}
|
||||||
</ul>
|
${h.hidden('mark-complete', value='true')}
|
||||||
|
<button type="submit">Mark Batch as Complete</button>
|
||||||
|
% endif
|
||||||
|
|
|
@ -96,6 +96,7 @@ class MasterView(View):
|
||||||
rows_bulk_deletable = False
|
rows_bulk_deletable = False
|
||||||
rows_default_pagesize = 20
|
rows_default_pagesize = 20
|
||||||
|
|
||||||
|
mobile_rows_filterable = False
|
||||||
mobile_rows_viewable = False
|
mobile_rows_viewable = False
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -206,11 +207,32 @@ class MasterView(View):
|
||||||
defaults.update(kwargs)
|
defaults.update(kwargs)
|
||||||
return defaults
|
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):
|
def make_mobile_filters(self):
|
||||||
"""
|
"""
|
||||||
Returns a set of filters for the mobile grid, if applicable.
|
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):
|
def preconfigure_mobile_grid(self, grid):
|
||||||
"""
|
"""
|
||||||
Optionally perform pre-configuration for the mobile grid, to establish
|
Optionally perform pre-configuration for the mobile grid, to establish
|
||||||
|
@ -588,14 +610,6 @@ class MasterView(View):
|
||||||
def get_mobile_row_data(self, parent):
|
def get_mobile_row_data(self, parent):
|
||||||
return self.get_row_data(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):
|
def make_mobile_row_grid(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Make a new (configured) rows grid instance for mobile.
|
Make a new (configured) rows grid instance for mobile.
|
||||||
|
@ -607,7 +621,7 @@ class MasterView(View):
|
||||||
kwargs.setdefault('request', self.request)
|
kwargs.setdefault('request', self.request)
|
||||||
kwargs.setdefault('model_class', self.model_row_class)
|
kwargs.setdefault('model_class', self.model_row_class)
|
||||||
kwargs = self.make_mobile_row_grid_kwargs(**kwargs)
|
kwargs = self.make_mobile_row_grid_kwargs(**kwargs)
|
||||||
factory = self.get_grid_factory()
|
factory = self.get_mobile_grid_factory()
|
||||||
grid = factory(**kwargs)
|
grid = factory(**kwargs)
|
||||||
self.configure_mobile_row_grid(grid)
|
self.configure_mobile_row_grid(grid)
|
||||||
grid.load_settings()
|
grid.load_settings()
|
||||||
|
|
|
@ -69,6 +69,33 @@ class MobileBatchStatusFilter(grids.filters.MobileFilter):
|
||||||
yield value, prettify(value)
|
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):
|
class ReceivingBatchView(PurchasingBatchView):
|
||||||
"""
|
"""
|
||||||
Master view for receiving batches
|
Master view for receiving batches
|
||||||
|
@ -82,6 +109,7 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
supports_mobile = True
|
supports_mobile = True
|
||||||
mobile_creatable = True
|
mobile_creatable = True
|
||||||
mobile_filterable = True
|
mobile_filterable = True
|
||||||
|
mobile_rows_filterable = True
|
||||||
mobile_rows_viewable = True
|
mobile_rows_viewable = True
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -96,6 +124,14 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
filters['status'] = MobileBatchStatusFilter('status', default_value='pending')
|
filters['status'] = MobileBatchStatusFilter('status', default_value='pending')
|
||||||
return filters
|
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):
|
def mobile_create(self):
|
||||||
"""
|
"""
|
||||||
Mobile view for creating a new receiving batch
|
Mobile view for creating a new receiving batch
|
||||||
|
@ -289,11 +325,17 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
row.credits.append(credit)
|
row.credits.append(credit)
|
||||||
return 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
|
@classmethod
|
||||||
def defaults(cls, config):
|
def defaults(cls, config):
|
||||||
route_prefix = cls.get_route_prefix()
|
route_prefix = cls.get_route_prefix()
|
||||||
url_prefix = cls.get_url_prefix()
|
url_prefix = cls.get_url_prefix()
|
||||||
model_key = cls.get_model_key()
|
model_key = cls.get_model_key()
|
||||||
|
permission_prefix = cls.get_permission_prefix()
|
||||||
row_permission_prefix = cls.get_row_permission_prefix()
|
row_permission_prefix = cls.get_row_permission_prefix()
|
||||||
|
|
||||||
# mobile lookup
|
# mobile lookup
|
||||||
|
@ -301,6 +343,11 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
config.add_view(cls, attr='mobile_lookup', route_name='mobile.{}.lookup'.format(route_prefix),
|
config.add_view(cls, attr='mobile_lookup', route_name='mobile.{}.lookup'.format(route_prefix),
|
||||||
renderer='json', permission='{}.view'.format(row_permission_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._purchasing_defaults(config)
|
||||||
cls._batch_defaults(config)
|
cls._batch_defaults(config)
|
||||||
cls._defaults(config)
|
cls._defaults(config)
|
||||||
|
|
Loading…
Reference in a new issue