Add toggle complete; improve quick entry for receiving batch API

This commit is contained in:
Lance Edgar 2019-11-13 14:05:38 -06:00
parent d42c2fabb9
commit 6a98dcc169
2 changed files with 37 additions and 0 deletions

View file

@ -262,6 +262,7 @@ class APIBatchRowView(APIBatchMixin, APIMasterView):
msg = "Feature is not implemented" msg = "Feature is not implemented"
return {'error': msg} return {'error': msg}
self.Session.flush()
result = self._get(obj=row) result = self._get(obj=row)
result['ok'] = True result['ok'] = True
return result return result

View file

@ -27,8 +27,10 @@ Tailbone Web API - Receiving Batches
from __future__ import unicode_literals, absolute_import from __future__ import unicode_literals, absolute_import
import six import six
import humanize
from rattail.db import model from rattail.db import model
from rattail.time import make_utc
from tailbone.api.batch import APIBatchView, APIBatchRowView from tailbone.api.batch import APIBatchView, APIBatchRowView
@ -41,6 +43,7 @@ class ReceivingBatchViews(APIBatchView):
permission_prefix = 'receiving' permission_prefix = 'receiving'
collection_url_prefix = '/receiving-batches' collection_url_prefix = '/receiving-batches'
object_url_prefix = '/receiving-batch' object_url_prefix = '/receiving-batch'
supports_toggle_complete = True
def normalize(self, batch): def normalize(self, batch):
data = super(ReceivingBatchViews, self).normalize(batch) data = super(ReceivingBatchViews, self).normalize(batch)
@ -48,6 +51,9 @@ class ReceivingBatchViews(APIBatchView):
data['vendor_uuid'] = batch.vendor.uuid data['vendor_uuid'] = batch.vendor.uuid
data['vendor_display'] = six.text_type(batch.vendor) data['vendor_display'] = six.text_type(batch.vendor)
data['department_uuid'] = batch.department_uuid
data['department_display'] = six.text_type(batch.department) if batch.department else None
return data return data
def get_purchase(self, uuid): def get_purchase(self, uuid):
@ -234,8 +240,38 @@ class ReceivingBatchRowViews(APIBatchRowView):
data['item_id'] = row.item_id data['item_id'] = row.item_id
data['upc'] = six.text_type(row.upc) data['upc'] = six.text_type(row.upc)
data['upc_pretty'] = row.upc.pretty() if row.upc else None data['upc_pretty'] = row.upc.pretty() if row.upc else None
data['brand_name'] = row.brand_name
data['description'] = row.description data['description'] = row.description
data['size'] = row.size
data['full_description'] = row.product.full_description if row.product else row.description data['full_description'] = row.product.full_description if row.product else row.description
data['case_quantity'] = row.case_quantity
data['unit_uom'] = 'EA' # TODO
data['order_quantities_known'] = batch.order_quantities_known
data['cases_shipped'] = row.cases_shipped
data['units_shipped'] = row.units_shipped
data['cases_received'] = row.cases_received
data['units_received'] = row.units_received
data['cases_damaged'] = row.cases_damaged
data['units_damaged'] = row.units_damaged
data['cases_expired'] = row.cases_expired
data['units_expired'] = row.units_expired
# TODO: surely the caller of API should determine this flag?
# maybe alert user if they've already received some of this product
alert_received = self.rattail_config.getbool('tailbone', 'receiving.alert_already_received',
default=False)
if alert_received:
msg = ''
if self.handler.get_units_confirmed(row):
msg = "You have already received some of this product; last update was {}.".format(
humanize.naturaltime(make_utc() - row.modified))
data['received_alert'] = msg
return data return data
def collection_get(self): def collection_get(self):