Add "auto-receive all items" support for receiving batch API

This commit is contained in:
Lance Edgar 2022-07-24 22:29:55 -05:00
parent f33d7b7f90
commit ad7b347e16
3 changed files with 26 additions and 22 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2021 Lance Edgar
# Copyright © 2010-2022 Lance Edgar
#
# This file is part of Rattail.
#
@ -74,6 +74,8 @@ class ReceivingBatchViews(APIBatchView):
data['invoice_total'] = batch.invoice_total
data['invoice_total_calculated'] = batch.invoice_total_calculated
data['can_auto_receive'] = self.handler.can_auto_receive(batch)
return data
def create_object(self, data):
@ -82,6 +84,15 @@ class ReceivingBatchViews(APIBatchView):
batch = super(ReceivingBatchViews, self).create_object(data)
return batch
def auto_receive(self):
"""
View which handles auto-marking as received, all items within
a pending batch.
"""
batch = self.get_object()
self.handler.auto_receive_all_items(batch)
return self._get(obj=batch)
def mark_receiving_complete(self):
"""
Mark the given batch as "receiving complete".
@ -136,6 +147,14 @@ class ReceivingBatchViews(APIBatchView):
collection_url_prefix = cls.get_collection_url_prefix()
object_url_prefix = cls.get_object_url_prefix()
# auto-receive
config.add_route('{}.auto_receive'.format(route_prefix),
'{}/{{uuid}}/auto-receive'.format(object_url_prefix))
config.add_view(cls, attr='auto_receive',
route_name='{}.auto_receive'.format(route_prefix),
permission='{}.auto_receive'.format(permission_prefix),
renderer='json')
# mark receiving complete
config.add_route('{}.mark_receiving_complete'.format(route_prefix), '{}/{{uuid}}/mark-receiving-complete'.format(object_url_prefix))
config.add_view(cls, attr='mark_receiving_complete', route_name='{}.mark_receiving_complete'.format(route_prefix),