Add basic support for viewing inventory batches on mobile

This commit is contained in:
Lance Edgar 2017-07-11 16:23:11 -05:00
parent 60104f05c7
commit 452cb99349
8 changed files with 82 additions and 12 deletions

View file

@ -212,8 +212,7 @@ class MobileFilter(GridFilter):
"""
default_verbs = ['equal']
def __init__(self, model_class, key, **kwargs):
self.model_class = model_class
def __init__(self, key, **kwargs):
kwargs.setdefault('default_active', True)
kwargs.setdefault('default_verb', 'equal')
super(MobileFilter, self).__init__(key, **kwargs)

View file

@ -0,0 +1,6 @@
## -*- coding: utf-8; -*-
<%inherit file="/mobile/newbatch/view.mako" />
<%def name="title()">${h.link_to("Inventory", url('mobile.batch.inventory'))} &raquo; ${instance.id_str}</%def>
${parent.body()}

View file

@ -0,0 +1,7 @@
## -*- coding: utf-8; -*-
<%inherit file="/mobile/newbatch/view_row.mako" />
## TODO: this is broken for actual page (header) title
<%def name="title()">${h.link_to("Inventory", url('mobile.batch.inventory'))} &raquo; ${h.link_to(instance.batch.id_str, url('mobile.batch.inventory.view', uuid=instance.batch_uuid))} &raquo; row ${row.sequence}</%def>
${parent.body()}

View file

@ -0,0 +1,9 @@
## -*- coding: utf-8; -*-
<%inherit file="/mobile/master/view.mako" />
${parent.body()}
% if master.has_rows:
<br />
${grid.render_complete()|n}
% endif

View file

@ -0,0 +1,4 @@
## -*- coding: utf-8; -*-
<%inherit file="/mobile/master/view_row.mako" />
${parent.body()}

View file

@ -74,6 +74,7 @@ class BatchMasterView(MasterView):
cloneable = False
supports_mobile = True
mobile_filterable = True
mobile_rows_viewable = True
def __init__(self, request):
super(BatchMasterView, self).__init__(request)
@ -180,6 +181,10 @@ class BatchMasterView(MasterView):
],
readonly=True)
def get_mobile_data(self, session=None):
return super(BatchMasterView, self).get_mobile_data(session=session)\
.order_by(self.model_class.id.desc())
def make_mobile_filters(self):
"""
Returns a set of filters for the mobile grid.
@ -421,6 +426,9 @@ class BatchMasterView(MasterView):
def make_row_grid_tools(self, batch):
return (self.make_default_row_grid_tools(batch) or '') + (self.make_batch_row_grid_tools(batch) or '')
def get_mobile_row_data(self, batch):
return super(BatchMasterView, self).get_mobile_row_data(batch)\
.order_by(self.model_row_class.sequence)
def redirect_after_edit(self, batch):
"""
If refresh flag is set, do that; otherwise go (back) to view/edit page.
@ -1168,6 +1176,10 @@ class MobileBatchStatusFilter(grids.filters.MobileFilter):
value_choices = ['pending', 'complete', 'executed', 'all']
def __init__(self, model_class, key, **kwargs):
self.model_class = model_class
super(MobileBatchStatusFilter, self).__init__(key, **kwargs)
def filter_equal(self, query, value):
if value == 'pending':

View file

@ -27,8 +27,10 @@ Views for inventory batches
from __future__ import unicode_literals, absolute_import
from rattail.db import model
from rattail.time import localtime
import formalchemy as fa
from webhelpers2.html import tags
from tailbone import forms
from tailbone.views.batch import BatchMasterView
@ -65,6 +67,10 @@ class InventoryBatchView(BatchMasterView):
g.mode,
], readonly=True)
def configure_mobile_grid(self, g):
super(InventoryBatchView, self).configure_mobile_grid(g)
g.listitem.set(renderer=InventoryBatchRenderer)
def _preconfigure_fieldset(self, fs):
super(InventoryBatchView, self)._preconfigure_fieldset(fs)
fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.INVENTORY_MODE),
@ -85,6 +91,22 @@ class InventoryBatchView(BatchMasterView):
fs.executed_by,
])
def configure_mobile_fieldset(self, fs):
fs.configure(include=[
fs.mode,
fs.rowcount,
fs.complete,
fs.executed,
fs.executed_by,
])
batch = fs.model
if not batch.executed:
del [fs.executed, fs.executed_by]
if not batch.complete:
del fs.complete
else:
del fs.complete
def _preconfigure_row_grid(self, g):
super(InventoryBatchView, self)._preconfigure_row_grid(g)
g.upc.set(label="UPC")
@ -113,6 +135,14 @@ class InventoryBatchView(BatchMasterView):
attrs['class_'] = 'warning'
return attrs
def render_mobile_row_listitem(self, row, **kwargs):
if row is None:
return ''
description = row.product.full_description if row.product else row.description
title = "({}) {}".format(row.upc.pretty(), description)
url = self.request.route_url('mobile.batch.inventory.rows.view', uuid=row.uuid)
return tags.link_to(title, url)
def _preconfigure_row_fieldset(self, fs):
super(InventoryBatchView, self)._preconfigure_row_fieldset(fs)
fs.upc.set(readonly=True, label="UPC", renderer=forms.renderers.GPCFieldRenderer,
@ -135,5 +165,18 @@ class InventoryBatchView(BatchMasterView):
])
class InventoryBatchRenderer(fa.FieldRenderer):
def render_readonly(self, **kwargs):
batch = self.raw_value
title = "({}) {} rows - {}, {}".format(
batch.id_str,
"?" if batch.rowcount is None else batch.rowcount,
batch.created_by,
localtime(self.request.rattail_config, batch.created).strftime('%Y-%m-%d'))
url = self.request.route_url('mobile.batch.inventory.view', uuid=batch.uuid)
return tags.link_to(title, url)
def includeme(config):
InventoryBatchView.defaults(config)

View file

@ -92,7 +92,6 @@ class ReceivingBatchView(PurchasingBatchView):
rows_deletable = False
mobile_creatable = True
mobile_rows_filterable = True
mobile_rows_viewable = True
@property
def batch_mode(self):
@ -159,11 +158,6 @@ class ReceivingBatchView(PurchasingBatchView):
kwargs['sms_transaction_number'] = batch.sms_transaction_number
return kwargs
def get_mobile_data(self, session=None):
# TODO: this hard-codes the sort by batch ID desc
return super(ReceivingBatchView, self).get_mobile_data(session=session)\
.order_by(model.PurchaseBatch.id.desc())
def configure_mobile_grid(self, g):
super(ReceivingBatchView, self).configure_mobile_grid(g)
g.listitem.set(renderer=ReceivingBatchRenderer)
@ -184,10 +178,6 @@ class ReceivingBatchView(PurchasingBatchView):
else:
del fs.complete
def get_mobile_row_data(self, batch):
return super(ReceivingBatchView, self).get_mobile_row_data(batch)\
.order_by(model.PurchaseBatchRow.sequence)
def render_mobile_row_listitem(self, row, **kwargs):
if row is None:
return ''