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()