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