Merge lp:~pedro.baeza/banking-addons/7.0-account_statement_ofx_import into lp:banking-addons/bank-statement-reconcile-70

Proposed by Pedro Manuel Baeza
Status: Merged
Merged at revision: 104
Proposed branch: lp:~pedro.baeza/banking-addons/7.0-account_statement_ofx_import
Merge into: lp:banking-addons/bank-statement-reconcile-70
Diff against target: 283 lines (+257/-0)
5 files modified
account_statement_ofx_import/__init__.py (+22/-0)
account_statement_ofx_import/__openerp__.py (+49/-0)
account_statement_ofx_import/parser/__init__.py (+22/-0)
account_statement_ofx_import/parser/ofx_parser.py (+118/-0)
account_statement_ofx_import/statement.py (+46/-0)
To merge this branch: bzr merge lp:~pedro.baeza/banking-addons/7.0-account_statement_ofx_import
Reviewer Review Type Date Requested Status
Leonardo Pistone test Needs Fixing
Omar (Pexego) code review, no test Approve
Joël Grand-Guillaume @ camptocamp code review, no tests Approve
Review via email: mp+193762@code.launchpad.net

Commit message

[ADD] account_statement_ofx_import: Allows to import OFX (Open Financial Exchange) statement files, using 'account_statement_base_import' generic inheritance mechanism to import statements.

Description of the change

[ADD] account_statement_ofx_import: Allows to import OFX (Open Financial Exchange) statement files, using 'account_statement_base_import' generic inheritance mechanism to import statements.

To post a comment you must log in.
Revision history for this message
Joël Grand-Guillaume @ camptocamp (jgrandguillaume-c2c) wrote :

Hi Perdo,

Thanks for the contribs !

LGTM,

review: Approve (code review, no tests)
Revision history for this message
Omar (Pexego) (omar7r) wrote :

LGTM

review: Approve (code review, no test)
Revision history for this message
Leonardo Pistone (lepistone) wrote :

Hi,

sorry for not having checked before, but the __openerp__ has a syntax error at line 66.

Thanks!

review: Needs Fixing (test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'account_statement_ofx_import'
2=== added file 'account_statement_ofx_import/__init__.py'
3--- account_statement_ofx_import/__init__.py 1970-01-01 00:00:00 +0000
4+++ account_statement_ofx_import/__init__.py 2013-11-04 12:25:22 +0000
5@@ -0,0 +1,22 @@
6+# -*- coding: utf-8 -*-
7+##############################################################################
8+#
9+# Author: Pedro Manuel Baeza Romero
10+# Copyright 2013 Servicios Tecnológicos Avanzados
11+#
12+# This program is free software: you can redistribute it and/or modify
13+# it under the terms of the GNU Affero General Public License as
14+# published by the Free Software Foundation, either version 3 of the
15+# License, or (at your option) any later version.
16+#
17+# This program is distributed in the hope that it will be useful,
18+# but WITHOUT ANY WARRANTY; without even the implied warranty of
19+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+# GNU Affero General Public License for more details.
21+#
22+# You should have received a copy of the GNU Affero General Public License
23+# along with this program. If not, see <http://www.gnu.org/licenses/>.
24+#
25+##############################################################################
26+import statement
27+import parser
28
29=== added file 'account_statement_ofx_import/__openerp__.py'
30--- account_statement_ofx_import/__openerp__.py 1970-01-01 00:00:00 +0000
31+++ account_statement_ofx_import/__openerp__.py 2013-11-04 12:25:22 +0000
32@@ -0,0 +1,49 @@
33+# -*- coding: utf-8 -*-
34+##############################################################################
35+#
36+# Author: Pedro Manuel Baeza Romero
37+# Copyright 2013 Servicios Tecnológicos Avanzados
38+# Financed by AB Internet (http://www.abinternet.co.uk/)
39+#
40+# This program is free software: you can redistribute it and/or modify
41+# it under the terms of the GNU Affero General Public License as
42+# published by the Free Software Foundation, either version 3 of the
43+# License, or (at your option) any later version.
44+#
45+# This program is distributed in the hope that it will be useful,
46+# but WITHOUT ANY WARRANTY; without even the implied warranty of
47+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
48+# GNU Affero General Public License for more details.
49+#
50+# You should have received a copy of the GNU Affero General Public License
51+# along with this program. If not, see <http://www.gnu.org/licenses/>.
52+#
53+##############################################################################
54+
55+{'name': "Bank statement OFX import",
56+ 'version': '1.0',
57+ 'author': 'Servicios Tecnológicos Avanzados - Pedro M. Baeza',
58+ 'maintainer': 'Pedro M. Baeza',
59+ 'category': 'Finance',
60+ 'complexity': 'normal',
61+ 'depends': [
62+ 'account_statement_base_import',
63+ ],
64+ 'external_dependencies': {
65+ 'python': ['ofxparse'],
66+ }
67+ 'description': """
68+ Allows to import OFX (Open Financial Exchange) statement files, using
69+ *account_statement_base_import* generic inheritance mechanism to import
70+ statements.
71+
72+ It requires ofxparse library to work.
73+ """,
74+ 'website': 'http://www.serviciosbaeza.com',
75+ 'data': [],
76+ 'test': [],
77+ 'installable': True,
78+ 'images': [],
79+ 'auto_install': False,
80+ 'license': 'AGPL-3',
81+}
82
83=== added directory 'account_statement_ofx_import/parser'
84=== added file 'account_statement_ofx_import/parser/__init__.py'
85--- account_statement_ofx_import/parser/__init__.py 1970-01-01 00:00:00 +0000
86+++ account_statement_ofx_import/parser/__init__.py 2013-11-04 12:25:22 +0000
87@@ -0,0 +1,22 @@
88+# -*- coding: utf-8 -*-
89+##############################################################################
90+#
91+# Author: Pedro Manuel Baeza Romero
92+# Copyright 2013 Servicios Tecnológicos Avanzados
93+#
94+# This program is free software: you can redistribute it and/or modify
95+# it under the terms of the GNU Affero General Public License as
96+# published by the Free Software Foundation, either version 3 of the
97+# License, or (at your option) any later version.
98+#
99+# This program is distributed in the hope that it will be useful,
100+# but WITHOUT ANY WARRANTY; without even the implied warranty of
101+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
102+# GNU Affero General Public License for more details.
103+#
104+# You should have received a copy of the GNU Affero General Public License
105+# along with this program. If not, see <http://www.gnu.org/licenses/>.
106+#
107+##############################################################################
108+from . import ofx_parser
109+
110
111=== added file 'account_statement_ofx_import/parser/ofx_parser.py'
112--- account_statement_ofx_import/parser/ofx_parser.py 1970-01-01 00:00:00 +0000
113+++ account_statement_ofx_import/parser/ofx_parser.py 2013-11-04 12:25:22 +0000
114@@ -0,0 +1,118 @@
115+# -*- coding: utf-8 -*-
116+##############################################################################
117+#
118+# Author: Pedro Manuel Baeza Romero
119+# Copyright 2013 Servicios Tecnológicos Avanzados
120+#
121+# This program is free software: you can redistribute it and/or modify
122+# it under the terms of the GNU Affero General Public License as
123+# published by the Free Software Foundation, either version 3 of the
124+# License, or (at your option) any later version.
125+#
126+# This program is distributed in the hope that it will be useful,
127+# but WITHOUT ANY WARRANTY; without even the implied warranty of
128+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
129+# GNU Affero General Public License for more details.
130+#
131+# You should have received a copy of the GNU Affero General Public License
132+# along with this program. If not, see <http://www.gnu.org/licenses/>.
133+#
134+##############################################################################
135+from openerp.tools.translate import _
136+from account_statement_base_import.parser import BankStatementImportParser
137+import tempfile
138+import datetime
139+
140+try:
141+ import ofxparse
142+except:
143+ raise Exception(_('Please install python lib ofxparse'))
144+
145+class OfxParser(BankStatementImportParser):
146+ """
147+ Class for defining parser for OFX file format.
148+ """
149+
150+ def __init__(self, parser_name, *args, **kwargs):
151+ """
152+ """
153+ super(OfxParser, self).__init__(parser_name, *args, **kwargs)
154+
155+ @classmethod
156+ def parser_for(cls, parser_name):
157+ """
158+ Used by the new_bank_statement_parser class factory. Return true if
159+ the providen name is 'ofx_so'.
160+ """
161+ return parser_name == 'ofx_so'
162+
163+ def _custom_format(self, *args, **kwargs):
164+ """
165+ No other work on data are needed in this parser.
166+ """
167+ return True
168+
169+ def _pre(self, *args, **kwargs):
170+ """
171+ No pre-treatment needed for this parser.
172+ """
173+ return True
174+
175+ def _parse(self, *args, **kwargs):
176+ """
177+ Launch the parsing itself.
178+ """
179+ ofx_file = tempfile.NamedTemporaryFile()
180+ ofx_file.seek(0)
181+ ofx_file.write(self.filebuffer)
182+ ofx_file.flush()
183+ ofx = ofxparse.OfxParser.parse(file(ofx_file.name))
184+ ofx_file.close()
185+ res = []
186+ for transaction in ofx.account.statement.transactions:
187+ res.append({
188+ 'date': transaction.date,
189+ 'amount': transaction.amount,
190+ 'ref': transaction.type,
191+ 'label': transaction.payee,
192+ })
193+ self.result_row_list = res
194+ return True
195+
196+ def _validate(self, *args, **kwargs):
197+ """
198+ Nothing to do here. ofxparse trigger possible format errors.
199+ """
200+ return True
201+
202+ def _post(self, *args, **kwargs):
203+ """
204+ Nothing is needed to do after parsing.
205+ """
206+ return True
207+
208+ def _post(self, *args, **kwargs):
209+ """
210+ Nothing to do.
211+ """
212+ return True
213+
214+ def get_st_line_vals(self, line, *args, **kwargs):
215+ """
216+ This method must return a dict of vals that can be passed to create
217+ method of statement line in order to record it. It is the
218+ responsibility of every parser to give this dict of vals, so each one
219+ can implement his own way of recording the lines.
220+ :param: line: a dict of vals that represent a line of
221+ result_row_list
222+ :return: dict of values to give to the create method of statement
223+ line
224+ """
225+ return {
226+ 'name': line.get('label', line.get('ref', '/')),
227+ 'date': line.get('date', datetime.datetime.now().date()),
228+ 'amount': line.get('amount', 0.0),
229+ 'ref': line.get('ref', '/'),
230+ 'label': line.get('label', ''),
231+ }
232+
233
234=== added file 'account_statement_ofx_import/statement.py'
235--- account_statement_ofx_import/statement.py 1970-01-01 00:00:00 +0000
236+++ account_statement_ofx_import/statement.py 2013-11-04 12:25:22 +0000
237@@ -0,0 +1,46 @@
238+# -*- coding: utf-8 -*-
239+##############################################################################
240+#
241+# Author: Pedro Manuel Baeza Romero
242+# Copyright 2013 Servicios Tecnológicos Avanzados
243+#
244+# This program is free software: you can redistribute it and/or modify
245+# it under the terms of the GNU Affero General Public License as
246+# published by the Free Software Foundation, either version 3 of the
247+# License, or (at your option) any later version.
248+#
249+# This program is distributed in the hope that it will be useful,
250+# but WITHOUT ANY WARRANTY; without even the implied warranty of
251+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
252+# GNU Affero General Public License for more details.
253+#
254+# You should have received a copy of the GNU Affero General Public License
255+# along with this program. If not, see <http://www.gnu.org/licenses/>.
256+#
257+##############################################################################
258+from openerp.tools.translate import _
259+from openerp.osv import fields, orm
260+
261+class AccountStatementProfil(orm.Model):
262+ _inherit = "account.statement.profile"
263+
264+ def get_import_type_selection(self, cr, uid, context=None):
265+ """
266+ Inherited from parent to add parser.
267+ """
268+ selection = super(AccountStatementProfil, self
269+ ).get_import_type_selection(cr, uid,
270+ context=context)
271+ selection.append(('ofx_so', _('OFX - Open Financial Exchange')))
272+ return selection
273+
274+ _columns = {
275+ 'import_type': fields.selection(
276+ get_import_type_selection,
277+ 'Type of import',
278+ required=True,
279+ help="Choose here the method by which you want to import bank"
280+ "statement for this profile."),
281+
282+ }
283+

Subscribers

People subscribed via source and target branches