Tweak some "unexpected item" logic for receiving API
This commit is contained in:
parent
6a98dcc169
commit
337422a619
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue