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
|
# is_unexpected
|
||||||
elif filtr['field'] == 'is_unexpected' and filtr['op'] == 'eq' and filtr['value'] is True:
|
elif filtr['field'] == 'is_unexpected' and filtr['op'] == 'eq' and filtr['value'] is True:
|
||||||
# looking for any rows which have "received" quantity but which
|
# looking for any rows which do *not* have "ordered/shipped" quantity
|
||||||
# do *not* have any "ordered" quantity
|
|
||||||
filters.extend([
|
filters.extend([
|
||||||
{'and': [
|
{'and': [
|
||||||
{'or': [
|
{'or': [
|
||||||
|
@ -200,12 +199,12 @@ class ReceivingBatchRowViews(APIBatchRowView):
|
||||||
{'field': 'units_ordered', 'op': '==', 'value': 0},
|
{'field': 'units_ordered', 'op': '==', 'value': 0},
|
||||||
]},
|
]},
|
||||||
{'or': [
|
{'or': [
|
||||||
{'field': 'cases_received', 'op': '!=', 'value': 0},
|
{'field': 'cases_shipped', 'op': 'is_null'},
|
||||||
{'field': 'units_received', 'op': '!=', 'value': 0},
|
{'field': 'cases_shipped', 'op': '==', 'value': 0},
|
||||||
{'field': 'cases_damaged', 'op': '!=', 'value': 0},
|
]},
|
||||||
{'field': 'units_damaged', 'op': '!=', 'value': 0},
|
{'or': [
|
||||||
{'field': 'cases_expired', 'op': '!=', 'value': 0},
|
{'field': 'units_shipped', 'op': 'is_null'},
|
||||||
{'field': 'units_expired', 'op': '!=', 'value': 0},
|
{'field': 'units_shipped', 'op': '==', 'value': 0},
|
||||||
]},
|
]},
|
||||||
]},
|
]},
|
||||||
])
|
])
|
||||||
|
@ -261,16 +260,31 @@ class ReceivingBatchRowViews(APIBatchRowView):
|
||||||
data['cases_expired'] = row.cases_expired
|
data['cases_expired'] = row.cases_expired
|
||||||
data['units_expired'] = row.units_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?
|
# TODO: surely the caller of API should determine this flag?
|
||||||
# maybe alert user if they've already received some of this product
|
# maybe alert user if they've already received some of this product
|
||||||
alert_received = self.rattail_config.getbool('tailbone', 'receiving.alert_already_received',
|
alert_received = self.rattail_config.getbool('tailbone', 'receiving.alert_already_received',
|
||||||
default=False)
|
default=False)
|
||||||
if alert_received:
|
if alert_received:
|
||||||
msg = ''
|
data['received_alert'] = None
|
||||||
if self.handler.get_units_confirmed(row):
|
if self.handler.get_units_confirmed(row):
|
||||||
msg = "You have already received some of this product; last update was {}.".format(
|
msg = "You have already received some of this product; last update was {}.".format(
|
||||||
humanize.naturaltime(make_utc() - row.modified))
|
humanize.naturaltime(make_utc() - row.modified))
|
||||||
data['received_alert'] = msg
|
data['received_alert'] = msg
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue