2017-06-22 02:35:41 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2016-08-17 16:52:36 -05:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2018-01-27 12:23:47 -06:00
|
|
|
# Copyright © 2010-2018 Lance Edgar
|
2016-08-17 16:52:36 -05:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
2017-07-06 23:47:56 -05:00
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
2016-08-17 16:52:36 -05:00
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2017-07-06 23:47:56 -05:00
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
2016-08-17 16:52:36 -05:00
|
|
|
#
|
2017-07-06 23:47:56 -05:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
2016-08-17 16:52:36 -05:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
|
|
|
Views for handheld batches
|
|
|
|
"""
|
|
|
|
|
|
|
|
from __future__ import unicode_literals, absolute_import
|
|
|
|
|
2016-11-19 18:09:14 -06:00
|
|
|
import os
|
|
|
|
|
2016-10-06 13:13:31 -05:00
|
|
|
from rattail.db import model
|
2016-08-17 16:52:36 -05:00
|
|
|
from rattail.util import OrderedDict
|
|
|
|
|
|
|
|
import formencode as fe
|
2017-07-06 20:13:42 -05:00
|
|
|
from webhelpers2.html import tags
|
2016-08-17 16:52:36 -05:00
|
|
|
|
2016-11-19 18:09:14 -06:00
|
|
|
from tailbone.db import Session
|
2018-02-04 11:09:35 -06:00
|
|
|
from tailbone.views.batch import FileBatchMasterView4 as FileBatchMasterView
|
2016-08-17 16:52:36 -05:00
|
|
|
|
|
|
|
|
|
|
|
ACTION_OPTIONS = OrderedDict([
|
|
|
|
('make_label_batch', "Make a new Label Batch"),
|
|
|
|
('make_inventory_batch', "Make a new Inventory Batch"),
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
|
|
class ExecutionOptions(fe.Schema):
|
|
|
|
allow_extra_fields = True
|
|
|
|
filter_extra_fields = True
|
|
|
|
action = fe.validators.OneOf(ACTION_OPTIONS)
|
|
|
|
|
|
|
|
|
|
|
|
class HandheldBatchView(FileBatchMasterView):
|
|
|
|
"""
|
|
|
|
Master view for handheld batches.
|
|
|
|
"""
|
|
|
|
model_class = model.HandheldBatch
|
2016-11-19 18:09:14 -06:00
|
|
|
default_handler_spec = 'rattail.batch.handheld:HandheldBatchHandler'
|
2016-08-17 16:52:36 -05:00
|
|
|
model_title_plural = "Handheld Batches"
|
|
|
|
route_prefix = 'batch.handheld'
|
|
|
|
url_prefix = '/batch/handheld'
|
|
|
|
execution_options_schema = ExecutionOptions
|
2016-08-23 13:11:13 -05:00
|
|
|
editable = False
|
2017-12-02 17:08:17 -06:00
|
|
|
results_executable = True
|
2016-08-23 13:11:13 -05:00
|
|
|
|
|
|
|
model_row_class = model.HandheldBatchRow
|
|
|
|
rows_creatable = False
|
|
|
|
rows_editable = True
|
2016-08-17 16:52:36 -05:00
|
|
|
|
2017-07-07 09:13:53 -05:00
|
|
|
grid_columns = [
|
|
|
|
'id',
|
|
|
|
'device_type',
|
|
|
|
'device_name',
|
|
|
|
'created',
|
|
|
|
'created_by',
|
|
|
|
'rowcount',
|
|
|
|
'status_code',
|
|
|
|
'executed',
|
|
|
|
]
|
|
|
|
|
2018-01-27 12:23:47 -06:00
|
|
|
form_fields = [
|
|
|
|
'id',
|
|
|
|
'device_type',
|
|
|
|
'device_name',
|
|
|
|
'filename',
|
|
|
|
'created',
|
|
|
|
'created_by',
|
|
|
|
'rowcount',
|
|
|
|
'status_code',
|
|
|
|
'executed',
|
|
|
|
'executed_by',
|
|
|
|
]
|
|
|
|
|
2018-02-04 11:09:35 -06:00
|
|
|
row_labels = {
|
|
|
|
'upc': "UPC",
|
|
|
|
}
|
|
|
|
|
2017-07-07 09:13:53 -05:00
|
|
|
row_grid_columns = [
|
|
|
|
'sequence',
|
|
|
|
'upc',
|
|
|
|
'brand_name',
|
|
|
|
'description',
|
|
|
|
'size',
|
|
|
|
'cases',
|
|
|
|
'units',
|
|
|
|
'status_code',
|
|
|
|
]
|
|
|
|
|
2018-02-04 11:09:35 -06:00
|
|
|
row_form_fields = [
|
|
|
|
'sequence',
|
|
|
|
'upc',
|
|
|
|
'brand_name',
|
|
|
|
'description',
|
|
|
|
'size',
|
|
|
|
'status_code',
|
|
|
|
'cases',
|
|
|
|
'units',
|
|
|
|
]
|
|
|
|
|
2016-08-17 16:52:36 -05:00
|
|
|
def configure_grid(self, g):
|
2017-07-07 09:13:53 -05:00
|
|
|
super(HandheldBatchView, self).configure_grid(g)
|
2017-06-22 02:35:41 -05:00
|
|
|
device_types = OrderedDict(sorted(self.enum.HANDHELD_DEVICE_TYPE.items(),
|
|
|
|
key=lambda item: item[1]))
|
2017-07-07 09:13:53 -05:00
|
|
|
g.set_enum('device_type', device_types)
|
|
|
|
|
|
|
|
def grid_extra_class(self, batch, i):
|
2017-06-21 15:36:32 -05:00
|
|
|
if batch.status_code is not None and batch.status_code != batch.STATUS_OK:
|
2017-07-07 09:13:53 -05:00
|
|
|
return 'notice'
|
2017-06-21 13:23:59 -05:00
|
|
|
|
2018-01-27 12:23:47 -06:00
|
|
|
def configure_form(self, f):
|
|
|
|
super(HandheldBatchView, self).configure_form(f)
|
|
|
|
batch = f.model_instance
|
|
|
|
|
|
|
|
# device_type
|
2017-06-22 02:35:41 -05:00
|
|
|
device_types = OrderedDict(sorted(self.enum.HANDHELD_DEVICE_TYPE.items(),
|
|
|
|
key=lambda item: item[1]))
|
2018-01-27 12:23:47 -06:00
|
|
|
f.set_enum('device_type', device_types)
|
|
|
|
f.widgets['device_type'].values.insert(0, ('', "(none)"))
|
2016-11-19 18:09:14 -06:00
|
|
|
|
2016-08-17 16:52:36 -05:00
|
|
|
if self.creating:
|
2018-01-27 12:23:47 -06:00
|
|
|
f.set_fields([
|
|
|
|
'filename',
|
|
|
|
'device_type',
|
|
|
|
'device_name',
|
|
|
|
])
|
|
|
|
|
|
|
|
if self.viewing:
|
|
|
|
if batch.inventory_batch:
|
|
|
|
f.append('inventory_batch')
|
|
|
|
f.set_renderer('inventory_batch', self.render_inventory_batch)
|
|
|
|
|
|
|
|
def render_inventory_batch(self, handheld_batch, field):
|
|
|
|
batch = handheld_batch.inventory_batch
|
|
|
|
if not batch:
|
|
|
|
return ""
|
|
|
|
text = batch.id_str
|
|
|
|
url = self.request.route_url('batch.inventory.view', uuid=batch.uuid)
|
|
|
|
return tags.link_to(text, url)
|
2016-08-17 16:52:36 -05:00
|
|
|
|
2016-11-19 18:09:14 -06:00
|
|
|
def get_batch_kwargs(self, batch):
|
|
|
|
kwargs = super(HandheldBatchView, self).get_batch_kwargs(batch)
|
|
|
|
kwargs['device_type'] = batch.device_type
|
|
|
|
kwargs['device_name'] = batch.device_name
|
|
|
|
return kwargs
|
|
|
|
|
2016-08-17 16:52:36 -05:00
|
|
|
def configure_row_grid(self, g):
|
2017-07-07 09:13:53 -05:00
|
|
|
super(HandheldBatchView, self).configure_row_grid(g)
|
|
|
|
g.set_type('cases', 'quantity')
|
|
|
|
g.set_type('units', 'quantity')
|
|
|
|
g.set_label('brand_name', "Brand")
|
|
|
|
|
|
|
|
def row_grid_extra_class(self, row, i):
|
2016-08-17 16:52:36 -05:00
|
|
|
if row.status_code == row.STATUS_PRODUCT_NOT_FOUND:
|
2017-07-07 09:13:53 -05:00
|
|
|
return 'warning'
|
2016-08-17 16:52:36 -05:00
|
|
|
|
2018-02-04 11:09:35 -06:00
|
|
|
def configure_row_form(self, f):
|
|
|
|
super(HandheldBatchView, self).configure_row_form(f)
|
|
|
|
|
|
|
|
# readonly fields
|
|
|
|
f.set_readonly('upc')
|
|
|
|
f.set_readonly('brand_name')
|
|
|
|
f.set_readonly('description')
|
|
|
|
f.set_readonly('size')
|
|
|
|
|
|
|
|
# upc
|
|
|
|
f.set_renderer('upc', self.render_upc)
|
|
|
|
|
|
|
|
def render_upc(self, row, field):
|
|
|
|
upc = row.upc
|
|
|
|
if not upc:
|
|
|
|
return ""
|
|
|
|
text = upc.pretty()
|
|
|
|
if row.product_uuid:
|
|
|
|
url = self.request.route_url('products.view', uuid=row.product_uuid)
|
|
|
|
return tags.link_to(text, url)
|
|
|
|
return text
|
2016-08-23 13:11:13 -05:00
|
|
|
|
2016-08-17 16:52:36 -05:00
|
|
|
def get_exec_options_kwargs(self, **kwargs):
|
|
|
|
kwargs['ACTION_OPTIONS'] = list(ACTION_OPTIONS.iteritems())
|
|
|
|
return kwargs
|
|
|
|
|
|
|
|
def get_execute_success_url(self, batch, result, **kwargs):
|
|
|
|
if kwargs['action'] == 'make_inventory_batch':
|
|
|
|
return self.request.route_url('batch.inventory.view', uuid=result.uuid)
|
|
|
|
elif kwargs['action'] == 'make_label_batch':
|
2017-06-21 15:36:32 -05:00
|
|
|
return self.request.route_url('labels.batch.view', uuid=result.uuid)
|
2016-08-17 16:52:36 -05:00
|
|
|
return super(HandheldBatchView, self).get_execute_success_url(batch)
|
|
|
|
|
2017-06-22 01:02:03 -05:00
|
|
|
def get_execute_results_success_url(self, result, **kwargs):
|
|
|
|
batch = result
|
|
|
|
return self.get_execute_success_url(batch, result, **kwargs)
|
|
|
|
|
2016-08-17 16:52:36 -05:00
|
|
|
|
|
|
|
def includeme(config):
|
|
|
|
HandheldBatchView.defaults(config)
|