From 006a7096eda9ee67c1e05a4390967de2239903a9 Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sat, 2 Mar 2019 18:07:07 -0600 Subject: [PATCH] Add ability to sort by Credits? column for receiving batch rows --- tailbone/views/purchasing/receiving.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tailbone/views/purchasing/receiving.py b/tailbone/views/purchasing/receiving.py index 68f469f3..40d0db29 100644 --- a/tailbone/views/purchasing/receiving.py +++ b/tailbone/views/purchasing/receiving.py @@ -748,6 +748,16 @@ class ReceivingBatchView(PurchasingBatchView): super(ReceivingBatchView, self).configure_row_grid(g) g.set_label('department_name', "Department") + # credits + # note that sorting by credits involves a subquery with group by clause. + # seems likely there may be a better way? but this seems to work fine + Credits = self.Session.query(model.PurchaseBatchCredit.row_uuid, + sa.func.count().label('credit_count'))\ + .group_by(model.PurchaseBatchCredit.row_uuid)\ + .subquery() + g.set_joiner('credits', lambda q: q.outerjoin(Credits)) + g.sorters['credits'] = lambda q, d: q.order_by(getattr(Credits.c.credit_count, d)()) + # hide 'ordered' columns for truck dump parent, if its "children first" # flag is set, since that batch type is only concerned with receiving batch = self.get_instance()