Various tweaks for support of native inventory

certaianly some other things made it in here too..
This commit is contained in:
Lance Edgar 2017-07-19 01:42:18 -05:00
parent eb68eec520
commit 61d504afb8
11 changed files with 129 additions and 16 deletions

View file

@ -72,6 +72,7 @@ class BatchMasterView(MasterView):
supports_mobile = True
mobile_filterable = True
mobile_rows_viewable = True
has_worksheet = False
def __init__(self, request):
super(BatchMasterView, self).__init__(request)
@ -422,6 +423,9 @@ class BatchMasterView(MasterView):
def editable_instance(self, batch):
return not bool(batch.executed)
def after_edit_row(self, row):
self.handler.refresh_row(row)
def executable(self, batch=None):
return self.handler.executable(batch)
@ -954,6 +958,17 @@ class BatchMasterView(MasterView):
config.add_view(cls, attr='prefill', route_name='{}.prefill'.format(route_prefix),
permission='{}.create'.format(permission_prefix))
# worksheet
if cls.has_worksheet:
config.add_tailbone_permission(permission_prefix, '{}.worksheet'.format(permission_prefix),
"Edit {} data as worksheet".format(model_title))
config.add_route('{}.worksheet'.format(route_prefix), '{}/{{{}}}/worksheet'.format(url_prefix, model_key))
config.add_view(cls, attr='worksheet', route_name='{}.worksheet'.format(route_prefix),
permission='{}.worksheet'.format(permission_prefix))
config.add_route('{}.worksheet_update'.format(route_prefix), '{}/{{{}}}/worksheet/update'.format(url_prefix, model_key))
config.add_view(cls, attr='worksheet_update', route_name='{}.worksheet_update'.format(route_prefix),
renderer='json', permission='{}.worksheet'.format(permission_prefix))
# refresh batch data
config.add_route('{}.refresh'.format(route_prefix), '{}/{{uuid}}/refresh'.format(url_prefix))
config.add_view(cls, attr='refresh', route_name='{}.refresh'.format(route_prefix),

View file

@ -103,6 +103,7 @@ class BatchMasterView2(MasterView2, BatchMasterView):
g.set_label('sequence', "Seq.")
g.set_label('status_code', "Status")
g.set_label('item_id', "Item ID")
def render_row_status(self, row, column):
code = row.status_code

View file

@ -59,10 +59,11 @@ class InventoryBatchView(BatchMasterView):
'id',
'created',
'created_by',
'mode',
'rowcount',
'total_cost',
'executed',
'executed_by',
'mode',
]
model_row_class = model.InventoryBatchRow
@ -71,18 +72,21 @@ class InventoryBatchView(BatchMasterView):
row_grid_columns = [
'sequence',
'upc',
'item_id',
'brand_name',
'description',
'size',
'cases',
'units',
'unit_cost',
'total_cost',
'status_code',
]
def configure_grid(self, g):
super(InventoryBatchView, self).configure_grid(g)
g.set_enum('mode', self.enum.INVENTORY_MODE)
g.set_type('total_cost', 'currency')
g.set_label('mode', "Count Mode")
def render_mobile_listitem(self, batch, i):
@ -96,6 +100,7 @@ class InventoryBatchView(BatchMasterView):
super(InventoryBatchView, self)._preconfigure_fieldset(fs)
fs.mode.set(renderer=forms.renderers.EnumFieldRenderer(self.enum.INVENTORY_MODE),
label="Count Mode")
fs.total_cost.set(readonly=True, renderer=forms.renderers.CurrencyFieldRenderer)
fs.append(fa.Field('handheld_batches', renderer=forms.renderers.HandheldBatchesFieldRenderer, readonly=True,
value=lambda b: b._handhelds))
@ -114,6 +119,22 @@ class InventoryBatchView(BatchMasterView):
fs.executed_by,
])
def save_edit_row_form(self, form):
row = form.fieldset.model
batch = row.batch
if batch.total_cost is not None and row.total_cost is not None:
batch.total_cost -= row.total_cost
return super(InventoryBatchView, self).save_edit_row_form(form)
def delete_row(self):
row = self.Session.query(model.InventoryBatchRow).get(self.request.matchdict['uuid'])
if not row:
raise self.notfound()
batch = row.batch
if batch.total_cost is not None and row.total_cost is not None:
batch.total_cost -= row.total_cost
return super(InventoryBatchView, self).delete_row()
def configure_mobile_fieldset(self, fs):
fs.configure(include=[
fs.mode,
@ -220,9 +241,15 @@ class InventoryBatchView(BatchMasterView):
def configure_row_grid(self, g):
super(InventoryBatchView, self).configure_row_grid(g)
g.set_renderer('cases', 'quantity')
g.set_renderer('units', 'quantity')
g.set_renderer('unit_cost', 'currency')
g.set_type('cases', 'quantity')
g.set_type('units', 'quantity')
g.set_type('unit_cost', 'currency')
g.set_type('total_cost', 'currency')
# TODO: i guess row grids don't support this properly yet?
# g.set_link('upc')
# g.set_link('item_id')
# g.set_link('description')
g.set_label('upc', "UPC")
g.set_label('brand_name', "Brand")
@ -242,10 +269,14 @@ class InventoryBatchView(BatchMasterView):
super(InventoryBatchView, self)._preconfigure_row_fieldset(fs)
fs.upc.set(readonly=True, label="UPC", renderer=forms.renderers.GPCFieldRenderer,
attrs={'link': lambda r: self.request.route_url('products.view', uuid=r.product_uuid)})
fs.item_id.set(readonly=True)
fs.brand_name.set(readonly=True)
fs.description.set(readonly=True)
fs.size.set(readonly=True)
fs.unit_cost.set(renderer=forms.renderers.CurrencyFieldRenderer)
fs.cases.set(renderer=forms.renderers.QuantityFieldRenderer)
fs.units.set(renderer=forms.renderers.QuantityFieldRenderer)
fs.unit_cost.set(readonly=True, renderer=forms.renderers.CurrencyFieldRenderer)
fs.total_cost.set(readonly=True, renderer=forms.renderers.CurrencyFieldRenderer)
def configure_row_fieldset(self, fs):
fs.configure(
@ -259,18 +290,22 @@ class InventoryBatchView(BatchMasterView):
fs.cases,
fs.units,
fs.unit_cost,
fs.total_cost,
])
@classmethod
def defaults(cls, config):
cls._inventory_defaults(config)
cls._batch_defaults(config)
cls._defaults(config)
@classmethod
def _inventory_defaults(cls, config):
model_key = cls.get_model_key()
route_prefix = cls.get_route_prefix()
url_prefix = cls.get_url_prefix()
row_permission_prefix = cls.get_row_permission_prefix()
cls._batch_defaults(config)
cls._defaults(config)
# mobile - make new row from UPC
config.add_route('mobile.{}.row_from_upc'.format(route_prefix), '/mobile{}/{{{}}}/row-from-upc'.format(url_prefix, model_key))
config.add_view(cls, attr='mobile_row_from_upc', route_name='mobile.{}.row_from_upc'.format(route_prefix),

View file

@ -1340,17 +1340,15 @@ class MasterView(View):
parent = self.get_parent(row)
return self.render_to_response('view_row', {
'instance': row,
'instance_title': self.get_row_instance_title(row),
'batch': row.batch,
'instance_title': self.get_instance_title(row.batch),
'instance_url': self.get_action_url('view', parent),
'instance_editable': self.row_editable(row),
'instance_deletable': self.row_deletable(row),
'rows_creatable': self.rows_creatable and self.rows_creatable_for(parent),
'model_title': self.get_row_model_title(),
'model_title_plural': self.get_row_model_title_plural(),
'parent_model_title': self.get_model_title(),
'index_url': self.get_action_url('view', parent),
'index_title': '{} {}'.format(
self.get_model_title(),
self.get_instance_title(parent)),
'action_url': self.get_row_action_url,
'form': form})

View file

@ -291,6 +291,10 @@ class ProductsView(MasterView):
fs.last_sold.set(readonly=True)
fs.append(fa.Field('current_price_ends', type=fa.types.DateTime, readonly=True,
value=lambda p: p.current_price.ends if p.current_price else None))
fs.append(fa.Field('inventory_on_hand', readonly=True, label="On Hand",
value=lambda p: p.inventory.on_hand if p.inventory else None))
fs.append(fa.Field('inventory_on_order', readonly=True, label="On Order",
value=lambda p: p.inventory.on_order if p.inventory else None))
def configure_fieldset(self, fs):
fs.configure(