restore performance improvements

@czue @twymer @dannyroberts 
Not sure how people feel about raw SQL but for the test data I have this drops the time from 14s in this function to 0.5s

```
100 cases
2 sections
10 products
11000 transactions

File: /home/skelly/projects/commcare-hq/corehq/ex-submodules/casexml/apps/stock/utils.py
Function: get_current_ledger_transactions_multi at line 52
Total time: 14.1789 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    52                                           def get_current_ledger_transactions_multi(case_ids):
    53                                               """
    54                                               Given a list of cases returns a dict of all current ledger data of the following format:
    55                                               {
    56                                                   "case_id": {
    57                                                       "section_id": {
    58                                                            "product_id": StockTransaction,
    59                                                            "product_id": StockTransaction,
    60                                                            ...
    61                                                       },
    62                                                       ...
    63                                                   },
    64                                                   ...
    65                                               }
    66                                               Where you get one stock transaction per product/section which is the last one seen.
    67                                               """
    68         1            0      0.0      0.0      if not case_ids:
    69                                                   return {}
    70                                           
    71         1            7      7.0      0.0      results = StockTransaction.objects.filter(
    72         1          719    719.0      0.0          case_id__in=case_ids
    73         1         2315   2315.0      0.0      ).values_list('case_id', 'section_id', 'product_id').distinct()
    74                                           
    75         1           36     36.0      0.0      ret = {case_id: {} for case_id in case_ids}
    76      1981        44179     22.3      0.3      for case_id, section_id, product_id in results:
    77      1980         7396      3.7      0.1          sections = ret[case_id].setdefault(section_id, {})
    78      1980     14124206   7133.4     99.6          sections[product_id] = StockTransaction.latest(case_id, section_id, product_id)
    79                                           
    80         1            1      1.0      0.0      return ret




with custom SQL
+++++++++++++++
+++++++++++++++

    File: /home/skelly/projects/commcare-hq/corehq/ex-submodules/casexml/apps/stock/utils.py
Function: get_current_ledger_transactions_multi at line 52
Total time: 0.515858 s

Line #      Hits         Time  Per Hit   % Time  Line Contents
==============================================================
    52                                           def get_current_ledger_transactions_multi(case_ids):
    53                                               """
    54                                               Given a list of cases returns a dict of all current ledger data of the following format:
    55                                               {
    56                                                   "case_id": {
    57                                                       "section_id": {
    58                                                            "product_id": StockTransaction,
    59                                                            "product_id": StockTransaction,
    60                                                            ...
    61                                                       },
    62                                                       ...
    63                                                   },
    64                                                   ...
    65                                               }
    66                                               Where you get one stock transaction per product/section which is the last one seen.
    67                                               """
    68         1            0      0.0      0.0      if not case_ids:
    69                                                   return {}
    70                                           
    71         1            6      6.0      0.0      relevant_transactions = StockTransaction.objects.raw(
    72                                                   """
    73                                                   SELECT MAX(stx.id) AS id FROM
    74                                                   (
    75                                                       SELECT case_id, product_id, section_id, MAX(sr.date) AS date
    76                                                       FROM stock_stocktransaction st JOIN stock_stockreport sr ON st.report_id = sr.id
    77                                                       WHERE case_id IN %s
    78                                                       GROUP BY case_id, section_id, product_id
    79                                                   ) AS x INNER JOIN stock_stocktransaction AS stx ON
    80                                                       stx.case_id = x.case_id
    81                                                       AND stx.product_id = x.product_id
    82                                                       AND stx.section_id = x.section_id
    83                                                   JOIN stock_stockreport str ON
    84                                                       str.date = x.date
    85                                                       AND stx.report_id = str.id
    86                                                   GROUP BY stx.case_id, stx.product_id, stx.section_id, str.date;
    87         1            1      1.0      0.0          """,
    88         1           49     49.0      0.0          [tuple(case_ids)]
    89                                               )
    90                                           
    91      1981       124560     62.9     24.1      transaction_ids = [tx.id for tx in relevant_transactions]
    92         1        14781  14781.0      2.9      results = StockTransaction.objects.filter(id__in=transaction_ids).select_related()
    93         1          171    171.0      0.0      ret = {case_id: {} for case_id in case_ids}
    94      1981       372190    187.9     72.1      for txn in results:
    95      1980         2448      1.2      0.5          sections = ret[txn.case_id].setdefault(txn.section_id, {})
    96      1980         1651      0.8      0.3          sections[txn.product_id] = txn
    97         1            1      1.0      0.0      return ret
```