Add ability to sort by Credits? column for receiving batch rows

This commit is contained in:
Lance Edgar 2019-03-02 18:07:07 -06:00
parent b7a026a7e8
commit 006a7096ed

View file

@ -748,6 +748,16 @@ class ReceivingBatchView(PurchasingBatchView):
super(ReceivingBatchView, self).configure_row_grid(g) super(ReceivingBatchView, self).configure_row_grid(g)
g.set_label('department_name', "Department") 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" # hide 'ordered' columns for truck dump parent, if its "children first"
# flag is set, since that batch type is only concerned with receiving # flag is set, since that batch type is only concerned with receiving
batch = self.get_instance() batch = self.get_instance()