From 337422a619f010a647cc3d9445258a74ba538ca3 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Fri, 15 Nov 2019 10:30:01 -0600 Subject: [PATCH] Tweak some "unexpected item" logic for receiving API --- tailbone/api/batch/receiving.py | 34 +++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/tailbone/api/batch/receiving.py b/tailbone/api/batch/receiving.py index 441b65d1..b422b9e1 100644 --- a/tailbone/api/batch/receiving.py +++ b/tailbone/api/batch/receiving.py @@ -187,8 +187,7 @@ class ReceivingBatchRowViews(APIBatchRowView): # is_unexpected elif filtr['field'] == 'is_unexpected' and filtr['op'] == 'eq' and filtr['value'] is True: - # looking for any rows which have "received" quantity but which - # do *not* have any "ordered" quantity + # looking for any rows which do *not* have "ordered/shipped" quantity filters.extend([ {'and': [ {'or': [ @@ -200,12 +199,12 @@ class ReceivingBatchRowViews(APIBatchRowView): {'field': 'units_ordered', 'op': '==', 'value': 0}, ]}, {'or': [ - {'field': 'cases_received', 'op': '!=', 'value': 0}, - {'field': 'units_received', 'op': '!=', 'value': 0}, - {'field': 'cases_damaged', 'op': '!=', 'value': 0}, - {'field': 'units_damaged', 'op': '!=', 'value': 0}, - {'field': 'cases_expired', 'op': '!=', 'value': 0}, - {'field': 'units_expired', 'op': '!=', 'value': 0}, + {'field': 'cases_shipped', 'op': 'is_null'}, + {'field': 'cases_shipped', 'op': '==', 'value': 0}, + ]}, + {'or': [ + {'field': 'units_shipped', 'op': 'is_null'}, + {'field': 'units_shipped', 'op': '==', 'value': 0}, ]}, ]}, ]) @@ -261,16 +260,31 @@ class ReceivingBatchRowViews(APIBatchRowView): data['cases_expired'] = row.cases_expired data['units_expired'] = row.units_expired + data['unexpected_alert'] = None + if batch.order_quantities_known and not row.cases_ordered and not row.units_ordered: + warn = True + if batch.is_truck_dump_parent() and row.product: + uuids = [child.uuid for child in batch.truck_dump_children] + if uuids: + count = self.Session.query(model.PurchaseBatchRow)\ + .filter(model.PurchaseBatchRow.batch_uuid.in_(uuids))\ + .filter(model.PurchaseBatchRow.product == row.product)\ + .count() + if count: + warn = False + if warn: + data['unexpected_alert'] = "This item was NOT on the original purchase order." + # 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 = '' + data['received_alert'] = None 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 + data['received_alert'] = msg return data