Merge lp:~wolfer7/wxbanker/bugfix-lp-534923 into lp:wxbanker

Proposed by wolfer
Status: Superseded
Proposed branch: lp:~wolfer7/wxbanker/bugfix-lp-534923
Merge into: lp:wxbanker
Diff against target: 158 lines (+68/-11)
5 files modified
test.py (+3/-0)
wxbanker/csvimporter.py (+17/-5)
wxbanker/csvimportframe.py (+6/-6)
wxbanker/data/fixtures/comdirect.csv (+33/-0)
wxbanker/tests/csvimportertests.py (+9/-0)
To merge this branch: bzr merge lp:~wolfer7/wxbanker/bugfix-lp-534923
Reviewer Review Type Date Requested Status
Michael Rooney Needs Fixing
Review via email: mp+20951@code.launchpad.net

This proposal has been superseded by a proposal from 2010-03-11.

Description of the change

changed csv-importer. previously one could only skip the first line, now it is possible to exactly specify how many rows should be skipped at the beginning of a file.

also added 'comdirect' to the shipped csv profiles.

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

Looks good, thanks for this feature and merge request! I can happily merge this after a few quick things. I would have just fixed the first two myself and pointed them out for your reference but the third one requires data from you.

 - It looks like there is a typo: "Linex to skip"
 - Instead of doing the counting logic like "if settings['linesToSkip']>linesSkipped: linesSkipped+=1", I would remove that logic and just change the for to "for row in csvReader[settings['linesToSkip']:]:"
 - All the included currencies should have tests with a small fixture CSV. It is fairly straightforward, see tests/csvimportertests.py for test examples, and you'll want to put an example CSV with a few transactions in the data/fixtures directory with the other .csv files.

Let me know if you have any questions and I look forward to merging this, thanks again!

review: Needs Fixing
605. By wolfgang steitz <wolfer@IBWKA1>

added comdirect import test

Revision history for this message
wolfer (wolfer7) wrote :

Thanks, for merging this. This significantly improves my wxbanker experience, cause I don't need to manually adjust my csv files anymore. I just did some fixes.

1. just a typo
2. csvReader[settings['linesToSkip']] does not work:
      csvimporter.py", line 86, in getTransactionsFromCSV
      for row in csvReader[settings['linesToSkip']]:
      TypeError: '_csv.reader' object is unsubscriptable
3. I added a sample csv to the data directory and also a test function. Seems to work.

I had some problems running the unit tests, so I added a simple test.py to the main directory. Unfortunately localetests.py crashes..

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'test.py'
2--- test.py 1970-01-01 00:00:00 +0000
3+++ test.py 2010-03-10 10:19:24 +0000
4@@ -0,0 +1,3 @@
5+#!/usr/bin/env python
6+from wxbanker.tests import alltests
7+alltests.main()
8
9=== modified file 'wxbanker/csvimporter.py'
10--- wxbanker/csvimporter.py 2009-12-06 03:40:42 +0000
11+++ wxbanker/csvimporter.py 2010-03-10 10:19:24 +0000
12@@ -40,7 +40,7 @@
13 "delimiter": ",",
14 "descriptionColumns": "2",
15 "encoding": "utf-8",
16- "skipFirstLine": True
17+ "linesToSkip": 1
18 },
19 "Sparkasse": {
20 "amountColumn": 9,
21@@ -50,7 +50,17 @@
22 "delimiter": ";",
23 "descriptionColumns": "6, 5 , 4",
24 "encoding": "utf-8",
25- "skipFirstLine": True
26+ "linesToSkip": 1
27+ },
28+ "comdirect": {
29+ "amountColumn": 5,
30+ "dateColumn": 1,
31+ "dateFormat": "%d.%m.%Y",
32+ "decimalSeparator": ",",
33+ "delimiter": ";",
34+ "descriptionColumns": "4 (3)",
35+ "encoding": "iso8859-1",
36+ "linesToSkip": 24
37 }
38 }
39
40@@ -72,11 +82,13 @@
41
42 transactions = []
43
44- firstLineSkipped = False
45+ linesSkipped = 0
46 for row in csvReader:
47- if settings['skipFirstLine'] and not firstLineSkipped:
48- firstLineSkipped = True
49+ if settings['linesToSkip']>linesSkipped:
50+ linesSkipped+=1
51 continue
52+ if len(row) == 0: #empty line, reached end of file
53+ break
54
55 # convert to python unicode strings
56 row = [unicode(s, "utf-8") for s in row]
57
58=== modified file 'wxbanker/csvimportframe.py'
59--- wxbanker/csvimportframe.py 2010-02-03 09:11:13 +0000
60+++ wxbanker/csvimportframe.py 2010-03-10 10:19:24 +0000
61@@ -124,9 +124,9 @@
62 sizer.SetFlexibleDirection(wx.HORIZONTAL)
63 staticBoxSizer.Add(sizer);
64
65- self.skipFirstLineCtrl = wx.CheckBox(topPanel)
66- sizer.Add(wx.StaticText(topPanel, label=_('Skip first line')), flag=wx.ALIGN_CENTER_VERTICAL)
67- sizer.Add(self.skipFirstLineCtrl, flag=wx.ALIGN_CENTER_VERTICAL)
68+ self.linesToSkipCtrl = wx.SpinCtrl(topPanel, size=(40,-1))
69+ sizer.Add(wx.StaticText(topPanel, label=_('Lines to skip')), flag=wx.ALIGN_CENTER_VERTICAL)
70+ sizer.Add(self.linesToSkipCtrl, flag=wx.ALIGN_CENTER_VERTICAL)
71
72 sizer.Add(wx.StaticText(topPanel, label=_('Encoding')), flag=wx.ALIGN_CENTER_VERTICAL)
73 self.fileEncodingCtrl = wx.ComboBox(topPanel, choices=self.encodings, size=(110,-1))
74@@ -200,7 +200,7 @@
75 self.dateFormatCtrl.Value = settings['dateFormat']
76 self.descriptionColumnCtrl.Value = settings['descriptionColumns']
77 self.delimiterCtrl.Value = settings['delimiter']
78- self.skipFirstLineCtrl.Value = settings['skipFirstLine']
79+ self.linesToSkipCtrl.Value = settings['linesToSkip']
80 self.fileEncodingCtrl.Value = settings['encoding']
81
82 def getDefaultSettings(self):
83@@ -212,7 +212,7 @@
84 settings['dateFormat'] = self.dateFormats[0]
85 settings['descriptionColumns'] = "3, 4 (5)"
86 settings['delimiter'] = ';'
87- settings['skipFirstLine'] = False
88+ settings['linesToSkip'] = 0
89 settings['encoding'] = 'utf-8'
90
91 return settings
92@@ -227,7 +227,7 @@
93 settings['descriptionColumns'] = self.descriptionColumnCtrl.Value
94 # delimiter must be 1-character string
95 settings['delimiter'] = str(self.delimiterCtrl.Value)
96- settings['skipFirstLine'] = self.skipFirstLineCtrl.Value
97+ settings['linesToSkip'] = self.linesToSkipCtrl.Value
98 settings['encoding'] = self.fileEncodingCtrl.Value
99
100 return settings
101
102=== added file 'wxbanker/data/fixtures/comdirect.csv'
103--- wxbanker/data/fixtures/comdirect.csv 1970-01-01 00:00:00 +0000
104+++ wxbanker/data/fixtures/comdirect.csv 2010-03-10 10:19:24 +0000
105@@ -0,0 +1,33 @@
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+"comdirect bank AG"
117+"UMSÄTZE: MAX MUSTERMANN"
118+"Erstellt am: 10.03.2010, 10:40 Uhr"
119+
120+"Kunden-Nummer:";"1234567"
121+"BLZ:";"20041234"
122+"Kontostand (Girokonto):";"1.234,56 EUR"
123+"Kontostand (VR-Konto):";"0,00 EUR"
124+
125+"Umsätze Girokonto";" - Zeitraum: 90 Tage"
126+
127+"Neuer Kontostand";"+1.234,56"
128+
129+"Buchungstag";"Valuta";"Vorgang";"Buchungstext";"Umsatz in EUR"
130+"09.03.2010";"09.03.2010";"Lastschrift Einzug";"Auftraggeber: FOO.DE Buchungstext: FOO.DE 12345467891234 Ref. AB123456789/00000 ";"-20,42"
131+"09.03.2010";"09.03.2010";"Übertrag/Überweisung";"Auftraggeber: Max Mustermann Buchungstext: Max Mustermann ABCD1234";"190,00"
132+"08.03.2010";"08.03.2010";"Lastschrift Einzug";"Auftraggeber: XYZ SAGT DANKE Buchungstext: XYZ SAGT DANKE EC 123456789 06.03 14.53 CE0 Ref. ABCDFER213456789/1480 ";"-32,27"
133+"05.03.2010";"05.03.2010";"Übertrag/Überweisung";"Empfänger: Max Mustermann Kto/IBAN: 123456789 BLZ/BIC: 123456789 Buchungstext: MAX MUSTERMANN COMDIREKT ÜBERTRAG AUF ";"-1500,00"
134+"05.03.2010";"05.03.2010";"Kontoübertrag";"Auftraggeber: Mustermann, Max Kto/IBAN: 123456789 BLZ/BIC: 123456789 Buchungstext: MUSTERMANN, MAX ÜBERTRAG AUF GIROKONTO KDN-REF 123456789 Ref. ABCDFER213456789/1 ";"1500,00"
135+
136+"Alter Kontostand";"+2.345,67"
137+
138+
139
140=== modified file 'wxbanker/tests/csvimportertests.py'
141--- wxbanker/tests/csvimportertests.py 2009-12-06 03:40:42 +0000
142+++ wxbanker/tests/csvimportertests.py 2010-03-10 10:19:24 +0000
143@@ -54,6 +54,15 @@
144 self.assertEqual(tran.Date, datetime.date(2009, 7, 17))
145 self.assertEqual(tran.Description, "PHONE CORP, ### , LASTSCHRIFT")
146 self.assertEqual(tran.Amount, -31.24)
147+
148+ def testCanImportComdirectData(self):
149+ transactions = self.getTransactions("comdirect")
150+ self.assertEqual(len(transactions), 5)
151+
152+ tran = transactions[2]
153+ self.assertEqual(tran.Date, datetime.date(2010, 3, 8))
154+ self.assertEqual(tran.Description, "Auftraggeber: XYZ SAGT DANKE Buchungstext: XYZ SAGT DANKE EC 123456789 06.03 14.53 CE0 Ref. ABCDFER213456789/1480 (Lastschrift Einzug)")
155+ self.assertEqual(tran.Amount, -32.27)
156
157
158 if __name__ == "__main__":

Subscribers

People subscribed via source and target branches

to all changes: