Commits

Dan Connolly  committed 4c2c19b

nest splits under transactions in finjax
- order by Transaction.guid to ensure splits are grouped by transaction
- order by account_type so that EXPENSE comes after BANK, CREDIT CARD
- order by Split.guid for stability of sort (for editing?)

  • Participants
  • Parent commits 613d5bc

Comments (0)

Files changed (3)

File finjax/finjax/models.py

         pattern = '%' + txt + '%'
 
         detail = session.query(Transaction.post_date.label('post_date'),
+                               Transaction.description.label('description'),
                                Split.guid.label('split_guid'),
                                Split.tx_guid.label('tx_guid'),
                                Split.account_guid.label('account_guid'),
                                Account.name.label('account_name'),
+                               Account.account_type.label('account_type'),
                                Split.memo.label('memo'),
                                Split.value_num.label('value_num'),
                                Split.value_denom.label('value_denom')).filter(
                        and_(Split.tx_guid == Transaction.guid,
                             Split.memo.like(pattern))
                        ).correlate(Transaction.__table__))
-            ).order_by(Transaction.post_date)
+            ).order_by(Transaction.post_date, Transaction.guid,
+                       Account.account_type, Split.guid)
 
 
 class Split(Base, GuidMixin):

File finjax/finjax/static/index.html

       <p><input name="q"/>
       <button ng:click="search(q)">Search</button></p>
       <table>
-	<tr><th>Date</th><th>Account</th><th>Description</th><th>Memo</th>
+	<tr><th>Date</th><th>Description / Memo</th>
+	<th>Account</th>
 	<th>Amount</th></tr>
 
-	<tr ng:repeat="d in matches">
-	  <td>{{d.post_date}}</td>
-	  <td>{{d.account_name}}</td>
-	  <td>{{d.description}}</td>
-	  <td>{{d.memo}}</td>
-	  <td class="money">{{d.value_num / d.value_denom }}</td>
-	</tr>
+	<tbody ng:repeat="tx in matches">
+	  <tr>
+	    <td>{{tx.post_date}}</td>
+	    <td>{{tx.description}}</td>
+	  </tr>
+	  <tr ng:repeat="d in tx.splits">
+	    <td>&#160;</td>
+	    <td>{{d.memo}}</td>
+	    <td>{{d.account_name}}</td>
+	    <td class="money">{{d.value_num / d.value_denom }}</td>
+	  </tr>
+	</tbody>
 
       </table>
     </div>

File finjax/finjax/views.py

+from itertools import groupby
+
 from pyramid.response import Response
 
 from sqlalchemy.exc import DBAPIError
             return Response(conn_err_msg,
                             content_type='text/plain', status_int=500)
 
-        # todo: return all the splits of the relevant transactions
-        return [jrec(m, dbq.column_descriptions) for m in matches]
+        def tx_obj(tx_guid, split_details):
+            return dict(tx_guid=tx_guid,
+                        post_date=split_details[0].post_date.isoformat(),
+                        description=split_details[0].description,
+                        splits=[
+                    dict(split_guid=d.split_guid,
+                         account_guid=d.account_guid,
+                         memo=d.memo,
+                         account_name=d.account_name,
+                         account_type=d.account_type,
+                         value_num=d.value_num,
+                         value_denom=d.value_denom)
+                    for d in split_details])
+
+        return [tx_obj(tx_guid, list(split_details))
+                for (tx_guid, split_details)
+                in groupby(matches, lambda m: m.tx_guid)]
 
 
 conn_err_msg = """\