Merge lp:~flimm/wxbanker/sort-bugfix into lp:wxbanker

Proposed by David D Lowe
Status: Merged
Merge reported by: Michael Rooney
Merged at revision: not available
Proposed branch: lp:~flimm/wxbanker/sort-bugfix
Merge into: lp:wxbanker
Diff against target: 109 lines (+35/-7)
2 files modified
wxbanker/tests/guitests.py (+22/-3)
wxbanker/transactionolv.py (+13/-4)
To merge this branch: bzr merge lp:~flimm/wxbanker/sort-bugfix
Reviewer Review Type Date Requested Status
Michael Rooney Approve
Review via email: mp+44689@code.launchpad.net

Description of the change

To post a comment you must log in.
Revision history for this message
Michael Rooney (mrooney) wrote :

Thanks for this, let me make sure it all works well and then merge it!

Revision history for this message
Michael Rooney (mrooney) wrote :

Thanks, sorry for the delay, merged!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'wxbanker/tests/guitests.py'
--- wxbanker/tests/guitests.py 2010-08-09 00:31:45 +0000
+++ wxbanker/tests/guitests.py 2010-12-25 13:52:00 +0000
@@ -227,6 +227,8 @@
227 227
228 a = self.Model.CreateAccount("B")228 a = self.Model.CreateAccount("B")
229 229
230 self.OLV.SortBy(self.OLV.COL_DATE)
231
230 # Super basic test, one transaction.232 # Super basic test, one transaction.
231 t1 = a.AddTransaction(1)233 t1 = a.AddTransaction(1)
232 self.assertEqual(totals(), [1])234 self.assertEqual(totals(), [1])
@@ -252,6 +254,23 @@
252 t3.Date = testbase.yesterday254 t3.Date = testbase.yesterday
253 self.assertEqual(totals(), [0.5, 2.25])255 self.assertEqual(totals(), [0.5, 2.25])
254 256
257 # Now add two transactions on the same date but in descending
258 # alphabetical order
259 t4 = a.AddTransaction(5, "BB", testbase.tomorrow)
260 t5 = a.AddTransaction(6, "AA", testbase.tomorrow)
261 self.assertEqual(totals(), [0.5, 2.25, 7.25, 13.25])
262
263 # Test that sorting by date always sorts transactions in the
264 # correct order, even transactions on the same date (bug #653697)
265 self.OLV.SortBy(self.OLV.COL_DESCRIPTION)
266 self.OLV.SortBy(self.OLV.COL_DATE)
267 self.assertEqual(totals(), [0.5, 2.25, 7.25, 13.25])
268
269 self.OLV.SortBy(self.OLV.COL_DESCRIPTION, ascending=False)
270 self.OLV.SortBy(self.OLV.COL_DATE, ascending=False)
271 self.assertEqual(totals(), [13.25, 7.25, 2.25, 0.5])
272
273
255 def testSearch(self):274 def testSearch(self):
256 a = self.Model.CreateAccount("A")275 a = self.Model.CreateAccount("A")
257 b = self.Model.CreateAccount("B")276 b = self.Model.CreateAccount("B")
@@ -262,7 +281,7 @@
262 t4 = b.AddTransaction(1, "Dog")281 t4 = b.AddTransaction(1, "Dog")
263 282
264 # Ensure b is selected283 # Ensure b is selected
265 self.assertEqual(self.OLV.GetObjects(), [t3, t4])284 self.assertEqual(set(self.OLV.GetObjects()), set([t3, t4]))
266 285
267 # Search for dog, make sure b's matching transaction is shown.286 # Search for dog, make sure b's matching transaction is shown.
268 Publisher.sendMessage("SEARCH.INITIATED", ("Dog", 1))287 Publisher.sendMessage("SEARCH.INITIATED", ("Dog", 1))
@@ -274,8 +293,8 @@
274 293
275 # Switch to all accounts, make sure we see both matches.294 # Switch to all accounts, make sure we see both matches.
276 Publisher.sendMessage("user.account changed", None)295 Publisher.sendMessage("user.account changed", None)
277 self.assertEqual(self.OLV.GetObjects(), [t2, t4])296 self.assertEqual(set(self.OLV.GetObjects()), set([t2, t4]))
278297
279298
280if __name__ == "__main__":299if __name__ == "__main__":
281 unittest.main()300 unittest.main()
282301
=== modified file 'wxbanker/transactionolv.py'
--- wxbanker/transactionolv.py 2010-10-02 18:08:31 +0000
+++ wxbanker/transactionolv.py 2010-12-25 13:52:00 +0000
@@ -58,12 +58,13 @@
5858
59 # Define some constants to use throughout.59 # Define some constants to use throughout.
60 self.COL_DATE = 060 self.COL_DATE = 0
61 self.COL_DESCRIPTION = 1
61 self.COL_AMOUNT = 262 self.COL_AMOUNT = 2
62 self.COL_TOTAL = 363 self.COL_TOTAL = 3
6364
64 # If you change these column names, update sizeAmounts()!65 # If you change these column names, update sizeAmounts()!
65 self.SetColumns([66 self.SetColumns([
66 ColumnDefn(_("Date"), valueGetter=self.getDateOf, valueSetter=self.setDateOf, width=dateWidth),67 ColumnDefn(_("Date"), valueGetter=self.getDateAndIDOf, valueSetter=self.setDateOf, stringConverter=self.renderDateIDTuple, editFormatter=self.renderEditDate, width=dateWidth),
67 ColumnDefn(_("Description"), valueGetter="Description", isSpaceFilling=True, editFormatter=self.renderEditDescription),68 ColumnDefn(_("Description"), valueGetter="Description", isSpaceFilling=True, editFormatter=self.renderEditDescription),
68 ColumnDefn(_("Amount"), "right", valueGetter="Amount", stringConverter=self.renderFloat, editFormatter=self.renderEditFloat),69 ColumnDefn(_("Amount"), "right", valueGetter="Amount", stringConverter=self.renderFloat, editFormatter=self.renderEditFloat),
69 ColumnDefn(_("Balance"), "right", valueGetter=self.getTotal, stringConverter=self.renderFloat, isEditable=False),70 ColumnDefn(_("Balance"), "right", valueGetter=self.getTotal, stringConverter=self.renderFloat, isEditable=False),
@@ -116,8 +117,10 @@
116 self.SortBy(self.SORT_COL)117 self.SortBy(self.SORT_COL)
117 self.updateTotals()118 self.updateTotals()
118119
119 def getDateOf(self, transaction):120 def getDateAndIDOf(self, transaction):
120 return str(transaction.Date)121 # A date and ID two-tuple is used to allow for correct sorting
122 # by date (bug #653697)
123 return (transaction.Date, transaction.ID)
121124
122 def setDateOf(self, transaction, date):125 def setDateOf(self, transaction, date):
123 transaction.Date = date126 transaction.Date = date
@@ -142,7 +145,10 @@
142 for i in range(1, len(self.GetObjects())):145 for i in range(1, len(self.GetObjects())):
143 a, b = b, self.GetObjectAt(i)146 a, b = b, self.GetObjectAt(i)
144 b._Total = a._Total + b.Amount147 b._Total = a._Total + b.Amount
145148
149 def renderDateIDTuple(self, pair):
150 return str(pair[0])
151
146 def renderFloat(self, floatVal):152 def renderFloat(self, floatVal):
147 if self.CurrentAccount:153 if self.CurrentAccount:
148 return self.CurrentAccount.float2str(floatVal)154 return self.CurrentAccount.float2str(floatVal)
@@ -151,6 +157,9 @@
151 # so that for multiple currencies they can be displayed differently when viewing all.157 # so that for multiple currencies they can be displayed differently when viewing all.
152 return self.BankController.Model.float2str(floatVal)158 return self.BankController.Model.float2str(floatVal)
153 159
160 def renderEditDate(self, transaction):
161 return str(transaction.Date)
162
154 def renderEditFloat(self, modelObj):163 def renderEditFloat(self, modelObj):
155 return "%.2f" % modelObj.Amount164 return "%.2f" % modelObj.Amount
156 165

Subscribers

People subscribed via source and target branches

to all changes: