Merge lp:~kolmis/wxbanker/movetransactions into lp:wxbanker/0.5

Proposed by Karel Kolman
Status: Merged
Merged at revision: not available
Proposed branch: lp:~kolmis/wxbanker/movetransactions
Merge into: lp:wxbanker/0.5
Diff against target: None lines
To merge this branch: bzr merge lp:~kolmis/wxbanker/movetransactions
Reviewer Review Type Date Requested Status
Michael Rooney Approve
Review via email: mp+4747@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Michael Rooney (mrooney) wrote :

Awesome, thanks! I've pushed this up with a minor follow up commit to remove the MoveTransaction method which didn't seem to be used, and was just going to recursively call itself anyway (a typo I imagine). I also got the list of transactions in a sightly cleaner way.

Thanks a ton for implementing this. Can I add you to the developers list yet? :) If so let me know which email address to use.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bankobjects.py'
2--- bankobjects.py 2009-03-13 18:58:29 +0000
3+++ bankobjects.py 2009-03-21 22:57:09 +0000
4@@ -230,29 +230,49 @@
5
6 # Ideally we don't load all the transactions here (this is silly on a transfer/move on an
7 # account that hasn't been viewed yet), but there's more important things for now.
8+ self._AddTransaction(transaction)
9+
10+ if source:
11+ return transaction, otherTrans
12+ else:
13+ return transaction
14+
15+ def _AddTransaction(self, transaction):
16+ """
17+ Add a transaction, send the message, update internal data
18+ """
19+
20 self.Transactions.append(transaction)
21-
22 Publisher.sendMessage("transaction.created", (self, transaction))
23-
24- # Update the balance.
25 self.Balance += transaction.Amount
26
27- if source:
28- return transaction, otherTrans
29- else:
30- return transaction
31-
32- def RemoveTransaction(self, transaction):
33+ def CheckTransactionAccount(self, transaction):
34 if transaction not in self.Transactions:
35 raise bankexceptions.InvalidTransactionException("Transaction does not exist in account '%s'" % self.Name)
36-
37+
38+ def RemoveTransaction(self, transaction):
39+ self.CheckTransactionAccount(transaction)
40 self.Store.RemoveTransaction(transaction)
41+ self._RemoveTransaction(transaction)
42+
43+ def _RemoveTransaction(self, transaction):
44+ """
45+ Remove a transaction, send the message, update internal data
46+ """
47+
48 Publisher.sendMessage("transaction.removed", (self, transaction))
49 self.Transactions.remove(transaction)
50-
51- # Update the balance.
52 self.Balance -= transaction.Amount
53
54+ def MoveTransactions(self, transactions, targetAccount):
55+ for t in transactions:
56+ self.CheckTransactionAccount(t)
57+
58+ self.Store.MoveTransactions(transactions, targetAccount)
59+ for t in transactions:
60+ self._RemoveTransaction(t)
61+ targetAccount._AddTransaction(t)
62+
63 def onTransactionAmountChanged(self, message):
64 transaction, difference = message.data
65 if self._Transactions is not None:
66
67=== modified file 'persistentstore.py'
68--- persistentstore.py 2009-03-07 02:23:22 +0000
69+++ persistentstore.py 2009-03-21 22:57:09 +0000
70@@ -125,7 +125,16 @@
71 # the controller already checks for existence of the ID though, so if this doesn't raise an exception, theoretically
72 # everything is fine. So just return True, as there we no errors that we are aware of.
73 return True
74-
75+
76+ def MoveTransaction(self, transaction, targetAccount):
77+ self.MoveTransaction([transaction], targetAccount)
78+
79+ def MoveTransactions(self, transactions, targetAccount):
80+ cursor = self.dbconn.cursor()
81+ self.dbconn.cursor().execute('UPDATE transactions SET accountId=? WHERE id IN (?)',
82+ (targetAccount.ID, ','.join([str(t.ID) for t in transactions])))
83+ self.commitIfAppropriate()
84+
85 def Save(self):
86 debug.debug("Committing db!")
87 self.dbconn.commit()
88
89=== modified file 'transactionolv.py'
90--- transactionolv.py 2009-03-10 20:36:19 +0000
91+++ transactionolv.py 2009-03-21 22:57:09 +0000
92@@ -195,13 +195,26 @@
93 # Always show the Remove context entry.
94 if len(transactions) == 1:
95 removeStr = _("Remove this transaction")
96+ moveStr = _("Move this transaction to account")
97 else:
98 removeStr = _("Remove these %i transactions") % len(transactions)
99+ moveStr = _("Move these %i transactions to account") % len(transactions)
100
101 removeItem = wx.MenuItem(menu, -1, removeStr)
102 menu.Bind(wx.EVT_MENU, lambda e: self.onRemoveTransactions(transactions), source=removeItem)
103 removeItem.SetBitmap(wx.ArtProvider.GetBitmap('wxART_delete'))
104 menu.AppendItem(removeItem)
105+
106+ moveToAccountItem = wx.MenuItem(menu, -1, moveStr)
107+ accountsMenu = wx.Menu()
108+ for account in self.BankController.Model.Accounts:
109+ accountItem = wx.MenuItem(menu, -1, account.GetName())
110+ accountsMenu.AppendItem(accountItem)
111+ accountsMenu.Bind(wx.EVT_MENU, lambda e, account=account: self.onMoveTransactions(transactions, account), source=accountItem)
112+ if account == self.CurrentAccount:
113+ accountItem.Enable(False)
114+ moveToAccountItem.SetSubMenu(accountsMenu)
115+ menu.AppendItem(moveToAccountItem)
116
117 # Show the menu and then destroy it afterwards.
118 self.PopupMenu(menu)
119@@ -233,6 +246,10 @@
120 #TODO: each call in the loop is going to force a freeze, resize, and thaw. Ideally batch this.
121 for transaction in transactions:
122 self.CurrentAccount.RemoveTransaction(transaction)
123+
124+ def onMoveTransactions(self, transactions, targetAccount):
125+ """Move the transactions to the target account."""
126+ self.CurrentAccount.MoveTransactions(transactions, targetAccount)
127
128 def frozenResize(self):
129 self.Parent.Layout()

Subscribers

People subscribed via source and target branches

to all changes: