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
1=== modified file 'wxbanker/tests/guitests.py'
2--- wxbanker/tests/guitests.py 2010-08-09 00:31:45 +0000
3+++ wxbanker/tests/guitests.py 2010-12-25 13:52:00 +0000
4@@ -227,6 +227,8 @@
5
6 a = self.Model.CreateAccount("B")
7
8+ self.OLV.SortBy(self.OLV.COL_DATE)
9+
10 # Super basic test, one transaction.
11 t1 = a.AddTransaction(1)
12 self.assertEqual(totals(), [1])
13@@ -252,6 +254,23 @@
14 t3.Date = testbase.yesterday
15 self.assertEqual(totals(), [0.5, 2.25])
16
17+ # Now add two transactions on the same date but in descending
18+ # alphabetical order
19+ t4 = a.AddTransaction(5, "BB", testbase.tomorrow)
20+ t5 = a.AddTransaction(6, "AA", testbase.tomorrow)
21+ self.assertEqual(totals(), [0.5, 2.25, 7.25, 13.25])
22+
23+ # Test that sorting by date always sorts transactions in the
24+ # correct order, even transactions on the same date (bug #653697)
25+ self.OLV.SortBy(self.OLV.COL_DESCRIPTION)
26+ self.OLV.SortBy(self.OLV.COL_DATE)
27+ self.assertEqual(totals(), [0.5, 2.25, 7.25, 13.25])
28+
29+ self.OLV.SortBy(self.OLV.COL_DESCRIPTION, ascending=False)
30+ self.OLV.SortBy(self.OLV.COL_DATE, ascending=False)
31+ self.assertEqual(totals(), [13.25, 7.25, 2.25, 0.5])
32+
33+
34 def testSearch(self):
35 a = self.Model.CreateAccount("A")
36 b = self.Model.CreateAccount("B")
37@@ -262,7 +281,7 @@
38 t4 = b.AddTransaction(1, "Dog")
39
40 # Ensure b is selected
41- self.assertEqual(self.OLV.GetObjects(), [t3, t4])
42+ self.assertEqual(set(self.OLV.GetObjects()), set([t3, t4]))
43
44 # Search for dog, make sure b's matching transaction is shown.
45 Publisher.sendMessage("SEARCH.INITIATED", ("Dog", 1))
46@@ -274,8 +293,8 @@
47
48 # Switch to all accounts, make sure we see both matches.
49 Publisher.sendMessage("user.account changed", None)
50- self.assertEqual(self.OLV.GetObjects(), [t2, t4])
51-
52+ self.assertEqual(set(self.OLV.GetObjects()), set([t2, t4]))
53+
54
55 if __name__ == "__main__":
56 unittest.main()
57
58=== modified file 'wxbanker/transactionolv.py'
59--- wxbanker/transactionolv.py 2010-10-02 18:08:31 +0000
60+++ wxbanker/transactionolv.py 2010-12-25 13:52:00 +0000
61@@ -58,12 +58,13 @@
62
63 # Define some constants to use throughout.
64 self.COL_DATE = 0
65+ self.COL_DESCRIPTION = 1
66 self.COL_AMOUNT = 2
67 self.COL_TOTAL = 3
68
69 # If you change these column names, update sizeAmounts()!
70 self.SetColumns([
71- ColumnDefn(_("Date"), valueGetter=self.getDateOf, valueSetter=self.setDateOf, width=dateWidth),
72+ ColumnDefn(_("Date"), valueGetter=self.getDateAndIDOf, valueSetter=self.setDateOf, stringConverter=self.renderDateIDTuple, editFormatter=self.renderEditDate, width=dateWidth),
73 ColumnDefn(_("Description"), valueGetter="Description", isSpaceFilling=True, editFormatter=self.renderEditDescription),
74 ColumnDefn(_("Amount"), "right", valueGetter="Amount", stringConverter=self.renderFloat, editFormatter=self.renderEditFloat),
75 ColumnDefn(_("Balance"), "right", valueGetter=self.getTotal, stringConverter=self.renderFloat, isEditable=False),
76@@ -116,8 +117,10 @@
77 self.SortBy(self.SORT_COL)
78 self.updateTotals()
79
80- def getDateOf(self, transaction):
81- return str(transaction.Date)
82+ def getDateAndIDOf(self, transaction):
83+ # A date and ID two-tuple is used to allow for correct sorting
84+ # by date (bug #653697)
85+ return (transaction.Date, transaction.ID)
86
87 def setDateOf(self, transaction, date):
88 transaction.Date = date
89@@ -142,7 +145,10 @@
90 for i in range(1, len(self.GetObjects())):
91 a, b = b, self.GetObjectAt(i)
92 b._Total = a._Total + b.Amount
93-
94+
95+ def renderDateIDTuple(self, pair):
96+ return str(pair[0])
97+
98 def renderFloat(self, floatVal):
99 if self.CurrentAccount:
100 return self.CurrentAccount.float2str(floatVal)
101@@ -151,6 +157,9 @@
102 # so that for multiple currencies they can be displayed differently when viewing all.
103 return self.BankController.Model.float2str(floatVal)
104
105+ def renderEditDate(self, transaction):
106+ return str(transaction.Date)
107+
108 def renderEditFloat(self, modelObj):
109 return "%.2f" % modelObj.Amount
110

Subscribers

People subscribed via source and target branches

to all changes: