Add basic support for viewing inventory batches on mobile
This commit is contained in:
parent
60104f05c7
commit
452cb99349
|
@ -212,8 +212,7 @@ class MobileFilter(GridFilter):
|
||||||
"""
|
"""
|
||||||
default_verbs = ['equal']
|
default_verbs = ['equal']
|
||||||
|
|
||||||
def __init__(self, model_class, key, **kwargs):
|
def __init__(self, key, **kwargs):
|
||||||
self.model_class = model_class
|
|
||||||
kwargs.setdefault('default_active', True)
|
kwargs.setdefault('default_active', True)
|
||||||
kwargs.setdefault('default_verb', 'equal')
|
kwargs.setdefault('default_verb', 'equal')
|
||||||
super(MobileFilter, self).__init__(key, **kwargs)
|
super(MobileFilter, self).__init__(key, **kwargs)
|
||||||
|
|
6
tailbone/templates/mobile/batch/inventory/view.mako
Normal file
6
tailbone/templates/mobile/batch/inventory/view.mako
Normal 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'))} » ${instance.id_str}</%def>
|
||||||
|
|
||||||
|
${parent.body()}
|
7
tailbone/templates/mobile/batch/inventory/view_row.mako
Normal file
7
tailbone/templates/mobile/batch/inventory/view_row.mako
Normal 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'))} » ${h.link_to(instance.batch.id_str, url('mobile.batch.inventory.view', uuid=instance.batch_uuid))} » row ${row.sequence}</%def>
|
||||||
|
|
||||||
|
${parent.body()}
|
9
tailbone/templates/mobile/newbatch/view.mako
Normal file
9
tailbone/templates/mobile/newbatch/view.mako
Normal 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
|
4
tailbone/templates/mobile/newbatch/view_row.mako
Normal file
4
tailbone/templates/mobile/newbatch/view_row.mako
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
## -*- coding: utf-8; -*-
|
||||||
|
<%inherit file="/mobile/master/view_row.mako" />
|
||||||
|
|
||||||
|
${parent.body()}
|
|
@ -74,6 +74,7 @@ class BatchMasterView(MasterView):
|
||||||
cloneable = False
|
cloneable = False
|
||||||
supports_mobile = True
|
supports_mobile = True
|
||||||
mobile_filterable = True
|
mobile_filterable = True
|
||||||
|
mobile_rows_viewable = True
|
||||||
|
|
||||||
def __init__(self, request):
|
def __init__(self, request):
|
||||||
super(BatchMasterView, self).__init__(request)
|
super(BatchMasterView, self).__init__(request)
|
||||||
|
@ -180,6 +181,10 @@ class BatchMasterView(MasterView):
|
||||||
],
|
],
|
||||||
readonly=True)
|
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):
|
def make_mobile_filters(self):
|
||||||
"""
|
"""
|
||||||
Returns a set of filters for the mobile grid.
|
Returns a set of filters for the mobile grid.
|
||||||
|
@ -421,6 +426,9 @@ class BatchMasterView(MasterView):
|
||||||
def make_row_grid_tools(self, batch):
|
def make_row_grid_tools(self, batch):
|
||||||
return (self.make_default_row_grid_tools(batch) or '') + (self.make_batch_row_grid_tools(batch) or '')
|
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):
|
def redirect_after_edit(self, batch):
|
||||||
"""
|
"""
|
||||||
If refresh flag is set, do that; otherwise go (back) to view/edit page.
|
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']
|
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):
|
def filter_equal(self, query, value):
|
||||||
|
|
||||||
if value == 'pending':
|
if value == 'pending':
|
||||||
|
|
|
@ -27,8 +27,10 @@ Views for inventory batches
|
||||||
from __future__ import unicode_literals, absolute_import
|
from __future__ import unicode_literals, absolute_import
|
||||||
|
|
||||||
from rattail.db import model
|
from rattail.db import model
|
||||||
|
from rattail.time import localtime
|
||||||
|
|
||||||
import formalchemy as fa
|
import formalchemy as fa
|
||||||
|
from webhelpers2.html import tags
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms
|
||||||
from tailbone.views.batch import BatchMasterView
|
from tailbone.views.batch import BatchMasterView
|
||||||
|
@ -65,6 +67,10 @@ class InventoryBatchView(BatchMasterView):
|
||||||
g.mode,
|
g.mode,
|
||||||
], readonly=True)
|
], 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):
|
def _preconfigure_fieldset(self, fs):
|
||||||
super(InventoryBatchView, self)._preconfigure_fieldset(fs)
|
super(InventoryBatchView, self)._preconfigure_fieldset(fs)
|
||||||
fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.INVENTORY_MODE),
|
fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.INVENTORY_MODE),
|
||||||
|
@ -85,6 +91,22 @@ class InventoryBatchView(BatchMasterView):
|
||||||
fs.executed_by,
|
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):
|
def _preconfigure_row_grid(self, g):
|
||||||
super(InventoryBatchView, self)._preconfigure_row_grid(g)
|
super(InventoryBatchView, self)._preconfigure_row_grid(g)
|
||||||
g.upc.set(label="UPC")
|
g.upc.set(label="UPC")
|
||||||
|
@ -113,6 +135,14 @@ class InventoryBatchView(BatchMasterView):
|
||||||
attrs['class_'] = 'warning'
|
attrs['class_'] = 'warning'
|
||||||
return attrs
|
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):
|
def _preconfigure_row_fieldset(self, fs):
|
||||||
super(InventoryBatchView, self)._preconfigure_row_fieldset(fs)
|
super(InventoryBatchView, self)._preconfigure_row_fieldset(fs)
|
||||||
fs.upc.set(readonly=True, label="UPC", renderer=forms.renderers.GPCFieldRenderer,
|
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):
|
def includeme(config):
|
||||||
InventoryBatchView.defaults(config)
|
InventoryBatchView.defaults(config)
|
||||||
|
|
|
@ -92,7 +92,6 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
rows_deletable = False
|
rows_deletable = False
|
||||||
mobile_creatable = True
|
mobile_creatable = True
|
||||||
mobile_rows_filterable = True
|
mobile_rows_filterable = True
|
||||||
mobile_rows_viewable = True
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def batch_mode(self):
|
def batch_mode(self):
|
||||||
|
@ -159,11 +158,6 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
kwargs['sms_transaction_number'] = batch.sms_transaction_number
|
kwargs['sms_transaction_number'] = batch.sms_transaction_number
|
||||||
return kwargs
|
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):
|
def configure_mobile_grid(self, g):
|
||||||
super(ReceivingBatchView, self).configure_mobile_grid(g)
|
super(ReceivingBatchView, self).configure_mobile_grid(g)
|
||||||
g.listitem.set(renderer=ReceivingBatchRenderer)
|
g.listitem.set(renderer=ReceivingBatchRenderer)
|
||||||
|
@ -184,10 +178,6 @@ class ReceivingBatchView(PurchasingBatchView):
|
||||||
else:
|
else:
|
||||||
del fs.complete
|
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):
|
def render_mobile_row_listitem(self, row, **kwargs):
|
||||||
if row is None:
|
if row is None:
|
||||||
return ''
|
return ''
|
||||||
|
|
Loading…
Reference in a new issue