From 053fc4eb5523fb14b751ab41ba06dbc54de5802b Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Tue, 10 Jul 2018 09:06:22 -0500 Subject: [PATCH] Sort mobile receiving rows by last modified instead of sequence because we now prefer to aggregate rows for that, at least by default --- tailbone/views/purchasing/receiving.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 452a8a75..f1b5d4eb 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -571,15 +571,22 @@ class ReceivingBatchView(PurchasingBatchView): def get_mobile_row_data(self, parent): query = self.get_row_data(parent) - aggregate_products = not bool(parent.truck_dump) # TODO: make this configurable? - if not aggregate_products: - query = query.order_by(model.PurchaseBatchRow.sequence.desc()) - return query + return self.sort_mobile_row_data(query) + + def sort_mobile_row_data(self, query): + return query.order_by(model.PurchaseBatchRow.modified.desc()) def render_mobile_row_listitem(self, row, i): description = row.product.full_description if row.product else row.description return "({}) {}".format(row.upc.pretty(), description) + def should_aggregate_products(self, batch): + """ + Must return a boolean indicating whether rows should be aggregated by + product for the given batch. + """ + return True + # TODO: this view can create new rows, with only a GET query. that should # probably be changed to require POST; for now we just require the "create # batch row" perm and call it good.. @@ -606,8 +613,7 @@ class ReceivingBatchView(PurchasingBatchView): .all() if rows: - aggregate_products = not bool(batch.truck_dump) # TODO: make this configurable? - if aggregate_products: + if self.should_aggregate_products(batch): if len(rows) > 1: log.warning("found multiple UPC matches for {} in batch {}: {}".format( upc, batch.id_str, batch))