From ad7b347e16155fdbb5b57843d6a753980a79865f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 24 Jul 2022 22:29:55 -0500 Subject: [PATCH] Add "auto-receive all items" support for receiving batch API --- tailbone/api/batch/receiving.py | 21 ++++++++++++++++++++- tailbone/templates/receiving/configure.mako | 6 +++--- tailbone/views/purchasing/receiving.py | 21 +++------------------ 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/tailbone/api/batch/receiving.py b/tailbone/api/batch/receiving.py index 905a0872..0ddda845 100644 --- a/tailbone/api/batch/receiving.py +++ b/tailbone/api/batch/receiving.py @@ -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), diff --git a/tailbone/templates/receiving/configure.mako b/tailbone/templates/receiving/configure.mako index e93dbd51..36ff5c39 100644 --- a/tailbone/templates/receiving/configure.mako +++ b/tailbone/templates/receiving/configure.mako @@ -129,7 +129,7 @@ - + - + - Allow "Quick Receive All" + Quick Receive "All or Nothing" diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index a250ba0c..eebb5855 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -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)