Add some convenience filters for receiving batch rows API
This commit is contained in:
parent
a9b740dcaa
commit
a096ce565e
|
@ -133,6 +133,100 @@ class ReceivingBatchRowViews(APIBatchRowView):
|
|||
object_url_prefix = '/receiving-batch-row'
|
||||
supports_quick_entry = True
|
||||
|
||||
def make_filter_spec(self):
|
||||
filters = super(ReceivingBatchRowViews, self).make_filter_spec()
|
||||
if filters:
|
||||
|
||||
# must translate certain convenience filters
|
||||
orig_filters, filters = filters, []
|
||||
for filtr in orig_filters:
|
||||
|
||||
# # is_received
|
||||
# # NOTE: this is only relevant for truck dump or "from scratch"
|
||||
# if filtr['field'] == 'is_received' and filtr['op'] == 'eq' and filtr['value'] is True:
|
||||
# filters.extend([
|
||||
# {'or': [
|
||||
# {'field': 'cases_received', 'op': '!=', 'value': 0},
|
||||
# {'field': 'units_received', 'op': '!=', 'value': 0},
|
||||
# ]},
|
||||
# ])
|
||||
|
||||
# is_incomplete
|
||||
if filtr['field'] == 'is_incomplete' and filtr['op'] == 'eq' and filtr['value'] is True:
|
||||
# looking for any rows with "ordered" quantity, but where the
|
||||
# status does *not* signify a "settled" row so to speak
|
||||
# TODO: would be nice if we had a simple flag to leverage?
|
||||
filters.extend([
|
||||
{'or': [
|
||||
{'field': 'cases_ordered', 'op': '!=', 'value': 0},
|
||||
{'field': 'units_ordered', 'op': '!=', 'value': 0},
|
||||
]},
|
||||
{'field': 'status_code', 'op': 'not_in', 'value': [
|
||||
model.PurchaseBatchRow.STATUS_OK,
|
||||
model.PurchaseBatchRow.STATUS_PRODUCT_NOT_FOUND,
|
||||
model.PurchaseBatchRow.STATUS_CASE_QUANTITY_DIFFERS,
|
||||
]},
|
||||
])
|
||||
|
||||
# is_invalid
|
||||
elif filtr['field'] == 'is_invalid' and filtr['op'] == 'eq' and filtr['value'] is True:
|
||||
filters.extend([
|
||||
{'field': 'status_code', 'op': 'in', 'value': [
|
||||
model.PurchaseBatchRow.STATUS_PRODUCT_NOT_FOUND,
|
||||
model.PurchaseBatchRow.STATUS_COST_NOT_FOUND,
|
||||
model.PurchaseBatchRow.STATUS_CASE_QUANTITY_UNKNOWN,
|
||||
model.PurchaseBatchRow.STATUS_CASE_QUANTITY_DIFFERS,
|
||||
]},
|
||||
])
|
||||
|
||||
# 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
|
||||
filters.extend([
|
||||
{'and': [
|
||||
{'or': [
|
||||
{'field': 'cases_ordered', 'op': 'is_null'},
|
||||
{'field': 'cases_ordered', 'op': '==', 'value': 0},
|
||||
]},
|
||||
{'or': [
|
||||
{'field': 'units_ordered', 'op': 'is_null'},
|
||||
{'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},
|
||||
]},
|
||||
]},
|
||||
])
|
||||
|
||||
# is_damaged
|
||||
elif filtr['field'] == 'is_damaged' and filtr['op'] == 'eq' and filtr['value'] is True:
|
||||
filters.extend([
|
||||
{'or': [
|
||||
{'field': 'cases_damaged', 'op': '!=', 'value': 0},
|
||||
{'field': 'units_damaged', 'op': '!=', 'value': 0},
|
||||
]},
|
||||
])
|
||||
|
||||
# is_expired
|
||||
elif filtr['field'] == 'is_expired' and filtr['op'] == 'eq' and filtr['value'] is True:
|
||||
filters.extend([
|
||||
{'or': [
|
||||
{'field': 'cases_expired', 'op': '!=', 'value': 0},
|
||||
{'field': 'units_expired', 'op': '!=', 'value': 0},
|
||||
]},
|
||||
])
|
||||
|
||||
else: # just some filter, use as-is
|
||||
filters.append(filtr)
|
||||
|
||||
return filters
|
||||
|
||||
def normalize(self, row):
|
||||
batch = row.batch
|
||||
data = super(ReceivingBatchRowViews, self).normalize(row)
|
||||
|
|
Loading…
Reference in a new issue