def get_inventory_items(request, pos, all_stock=False): client = get_qbo_client(get_callback_url(request)) results = Item.query( 'SELECT * from Item WHERE Active = true STARTPOSITION %s MAXRESULTS %s' % (pos, settings.QBO_MAX_RESULTS), qb=client) # conditionally return all items regardless if they're in stock or not if all_stock: return results # limit items that are in stock return [r for r in results if r.QtyOnHand > 0]