Add some API views for receiving, and vendor autocomplete
lots more to do yet, for those...
This commit is contained in:
parent
afdd294c60
commit
3514c4050e
7 changed files with 409 additions and 130 deletions
|
@ -29,119 +29,50 @@ from __future__ import unicode_literals, absolute_import
|
|||
import six
|
||||
|
||||
from rattail.db import model
|
||||
from rattail.time import localtime
|
||||
|
||||
from cornice import resource
|
||||
|
||||
from tailbone.api.batch import BatchAPIMasterView
|
||||
from tailbone.api.batch import APIBatchView, APIBatchRowView
|
||||
|
||||
|
||||
class LabelBatchViews(BatchAPIMasterView):
|
||||
class LabelBatchViews(APIBatchView):
|
||||
|
||||
model_class = model.LabelBatch
|
||||
default_handler_spec = 'rattail.batch.labels:LabelBatchHandler'
|
||||
route_prefix = 'labelbatchviews'
|
||||
permission_prefix = 'labels.batch'
|
||||
collection_url_prefix = '/label-batches'
|
||||
object_url_prefix = '/label-batch'
|
||||
supports_toggle_complete = True
|
||||
|
||||
def pretty_datetime(self, dt):
|
||||
if not dt:
|
||||
return ""
|
||||
return dt.strftime('%Y-%m-%d @ %I:%M %p')
|
||||
|
||||
def normalize(self, batch):
|
||||
|
||||
created = batch.created
|
||||
created = localtime(self.rattail_config, created, from_utc=True)
|
||||
created = self.pretty_datetime(created)
|
||||
|
||||
executed = batch.executed
|
||||
if executed:
|
||||
executed = localtime(self.rattail_config, executed, from_utc=True)
|
||||
executed = self.pretty_datetime(executed)
|
||||
|
||||
return {
|
||||
'uuid': batch.uuid,
|
||||
'_str': six.text_type(batch),
|
||||
'id': batch.id,
|
||||
'id_str': batch.id_str,
|
||||
'description': batch.description,
|
||||
'notes': batch.notes,
|
||||
'rowcount': batch.rowcount,
|
||||
'created': created,
|
||||
'created_by_uuid': batch.created_by.uuid,
|
||||
'created_by_display': six.text_type(batch.created_by),
|
||||
'complete': batch.complete,
|
||||
'executed': executed,
|
||||
'executed_by_uuid': batch.executed_by_uuid,
|
||||
'executed_by_display': six.text_type(batch.executed_by or ''),
|
||||
}
|
||||
|
||||
def collection_get(self):
|
||||
return self._collection_get()
|
||||
|
||||
def collection_post(self):
|
||||
return self._collection_post()
|
||||
|
||||
def update_object(self, batch, data):
|
||||
|
||||
# assign some default values for new batch
|
||||
if not batch.uuid:
|
||||
batch.created_by_uuid = self.request.user.uuid
|
||||
if batch.rowcount is None:
|
||||
batch.rowcount = 0
|
||||
|
||||
return super(LabelBatchViews, self).update_object(batch, data)
|
||||
|
||||
def get(self):
|
||||
return self._get()
|
||||
|
||||
# @view(permission='labels.batch.edit')
|
||||
# def post(self):
|
||||
# return self._post()
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
|
||||
# label batches
|
||||
resource.add_view(cls.collection_get, permission='labels.batch.list')
|
||||
resource.add_view(cls.collection_post, permission='labels.batch.create')
|
||||
resource.add_view(cls.get, permission='labels.batch.view')
|
||||
batch_resource = resource.add_resource(cls, collection_path='/label-batches', path='/label-batch/{uuid}')
|
||||
config.add_cornice_resource(batch_resource)
|
||||
|
||||
cls._batch_defaults(config)
|
||||
|
||||
|
||||
class LabelBatchRowViews(BatchAPIMasterView):
|
||||
class LabelBatchRowViews(APIBatchRowView):
|
||||
|
||||
model_class = model.LabelBatchRow
|
||||
default_handler_spec = 'rattail.batch.labels:LabelBatchHandler'
|
||||
route_prefix = 'api.label_batch_rows'
|
||||
permission_prefix = 'labels.batch'
|
||||
collection_url_prefix = '/label-batch-rows'
|
||||
object_url_prefix = '/label-batch-row'
|
||||
supports_quick_entry = True
|
||||
|
||||
def normalize(self, row):
|
||||
batch = row.batch
|
||||
return {
|
||||
'uuid': row.uuid,
|
||||
'_str': six.text_type(row),
|
||||
'_parent_str': six.text_type(batch),
|
||||
'_parent_uuid': batch.uuid,
|
||||
'batch_uuid': batch.uuid,
|
||||
'batch_id': batch.id,
|
||||
'batch_id_str': batch.id_str,
|
||||
'batch_description': batch.description,
|
||||
'sequence': row.sequence,
|
||||
'item_id': row.item_id,
|
||||
'upc': six.text_type(row.upc),
|
||||
'upc_pretty': row.upc.pretty() if row.upc else None,
|
||||
'description': row.description,
|
||||
'full_description': row.product.full_description if row.product else row.description,
|
||||
'status_code': row.status_code,
|
||||
'status_display': row.STATUS.get(row.status_code, six.text_type(row.status_code)),
|
||||
}
|
||||
data = super(LabelBatchRowViews, self).normalize(row)
|
||||
|
||||
data['item_id'] = row.item_id
|
||||
data['upc'] = six.text_type(row.upc)
|
||||
data['upc_pretty'] = row.upc.pretty() if row.upc else None
|
||||
data['description'] = row.description
|
||||
data['full_description'] = row.product.full_description if row.product else row.description
|
||||
return data
|
||||
|
||||
def collection_get(self):
|
||||
return self._collection_get()
|
||||
|
@ -149,18 +80,6 @@ class LabelBatchRowViews(BatchAPIMasterView):
|
|||
def get(self):
|
||||
return self._get()
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
permission_prefix = cls.get_permission_prefix()
|
||||
|
||||
# label batch rows
|
||||
resource.add_view(cls.collection_get, permission='{}.view'.format(permission_prefix))
|
||||
resource.add_view(cls.get, permission='{}.view'.format(permission_prefix))
|
||||
rows_resource = resource.add_resource(cls, collection_path='/label-batch-rows', path='/label-batch-row/{uuid}')
|
||||
config.add_cornice_resource(rows_resource)
|
||||
|
||||
cls._batch_defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
LabelBatchViews.defaults(config)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue