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),

View file

@ -129,7 +129,7 @@
</b-checkbox>
</b-field>
<b-field>
<b-field message="If set, one or more &quot;quick receive&quot; buttons will be available for mobile receiving.">
<b-checkbox name="rattail.batch.purchase.mobile_quick_receive"
v-model="simpleSettings['rattail.batch.purchase.mobile_quick_receive']"
native-value="true"
@ -138,12 +138,12 @@
</b-checkbox>
</b-field>
<b-field>
<b-field message="If set, only a &quot;quick receive all&quot; button will be shown. Only applicable if quick receive (above) is enabled.">
<b-checkbox name="rattail.batch.purchase.mobile_quick_receive_all"
v-model="simpleSettings['rattail.batch.purchase.mobile_quick_receive_all']"
native-value="true"
@input="settingsNeedSaved = true">
Allow "Quick Receive All"
Quick Receive "All or Nothing"
</b-checkbox>
</b-field>

View file

@ -129,9 +129,9 @@ class ReceivingBatchView(PurchasingBatchView):
'vendor_contact',
'vendor_phone',
'date_ordered',
'date_received',
'po_number',
'po_total',
'date_received',
'invoice_date',
'invoice_number',
'invoice_total',
@ -1824,22 +1824,7 @@ class ReceivingBatchView(PurchasingBatchView):
return pod.get_image_url(self.rattail_config, row.upc)
def can_auto_receive(self, batch):
if batch.executed:
return False
if batch.complete:
return False
if batch.is_truck_dump_related():
if not batch.is_truck_dump_parent():
return False
if not batch.truck_dump_children_first():
return False
# only auto-receive once per batch
if batch.get_param('auto_received'):
return False
return True
return self.handler.can_auto_receive(batch)
def auto_receive(self):
"""
@ -1865,7 +1850,7 @@ class ReceivingBatchView(PurchasingBatchView):
"""
session = RattailSession()
batch = session.query(model.PurchaseBatch).get(uuid)
user = session.query(model.User).get(user_uuid)
# user = session.query(model.User).get(user_uuid)
try:
self.handler.auto_receive_all_items(batch, progress=progress)