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
=== added directory 'account_statement_ofx_import'
=== added file 'account_statement_ofx_import/__init__.py'
--- account_statement_ofx_import/__init__.py 1970-01-01 00:00:00 +0000
+++ account_statement_ofx_import/__init__.py 2013-11-04 12:25:22 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Pedro Manuel Baeza Romero
5# Copyright 2013 Servicios Tecnológicos Avanzados
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21import statement
22import parser
023
=== added file 'account_statement_ofx_import/__openerp__.py'
--- account_statement_ofx_import/__openerp__.py 1970-01-01 00:00:00 +0000
+++ account_statement_ofx_import/__openerp__.py 2013-11-04 12:25:22 +0000
@@ -0,0 +1,49 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Pedro Manuel Baeza Romero
5# Copyright 2013 Servicios Tecnológicos Avanzados
6# Financed by AB Internet (http://www.abinternet.co.uk/)
7#
8# This program is free software: you can redistribute it and/or modify
9# it under the terms of the GNU Affero General Public License as
10# published by the Free Software Foundation, either version 3 of the
11# License, or (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU Affero General Public License for more details.
17#
18# You should have received a copy of the GNU Affero General Public License
19# along with this program. If not, see <http://www.gnu.org/licenses/>.
20#
21##############################################################################
22
23{'name': "Bank statement OFX import",
24 'version': '1.0',
25 'author': 'Servicios Tecnológicos Avanzados - Pedro M. Baeza',
26 'maintainer': 'Pedro M. Baeza',
27 'category': 'Finance',
28 'complexity': 'normal',
29 'depends': [
30 'account_statement_base_import',
31 ],
32 'external_dependencies': {
33 'python': ['ofxparse'],
34 }
35 'description': """
36 Allows to import OFX (Open Financial Exchange) statement files, using
37 *account_statement_base_import* generic inheritance mechanism to import
38 statements.
39
40 It requires ofxparse library to work.
41 """,
42 'website': 'http://www.serviciosbaeza.com',
43 'data': [],
44 'test': [],
45 'installable': True,
46 'images': [],
47 'auto_install': False,
48 'license': 'AGPL-3',
49}
050
=== added directory 'account_statement_ofx_import/parser'
=== added file 'account_statement_ofx_import/parser/__init__.py'
--- account_statement_ofx_import/parser/__init__.py 1970-01-01 00:00:00 +0000
+++ account_statement_ofx_import/parser/__init__.py 2013-11-04 12:25:22 +0000
@@ -0,0 +1,22 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Pedro Manuel Baeza Romero
5# Copyright 2013 Servicios Tecnológicos Avanzados
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21from . import ofx_parser
22
023
=== added file 'account_statement_ofx_import/parser/ofx_parser.py'
--- account_statement_ofx_import/parser/ofx_parser.py 1970-01-01 00:00:00 +0000
+++ account_statement_ofx_import/parser/ofx_parser.py 2013-11-04 12:25:22 +0000
@@ -0,0 +1,118 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Pedro Manuel Baeza Romero
5# Copyright 2013 Servicios Tecnológicos Avanzados
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21from openerp.tools.translate import _
22from account_statement_base_import.parser import BankStatementImportParser
23import tempfile
24import datetime
25
26try:
27 import ofxparse
28except:
29 raise Exception(_('Please install python lib ofxparse'))
30
31class OfxParser(BankStatementImportParser):
32 """
33 Class for defining parser for OFX file format.
34 """
35
36 def __init__(self, parser_name, *args, **kwargs):
37 """
38 """
39 super(OfxParser, self).__init__(parser_name, *args, **kwargs)
40
41 @classmethod
42 def parser_for(cls, parser_name):
43 """
44 Used by the new_bank_statement_parser class factory. Return true if
45 the providen name is 'ofx_so'.
46 """
47 return parser_name == 'ofx_so'
48
49 def _custom_format(self, *args, **kwargs):
50 """
51 No other work on data are needed in this parser.
52 """
53 return True
54
55 def _pre(self, *args, **kwargs):
56 """
57 No pre-treatment needed for this parser.
58 """
59 return True
60
61 def _parse(self, *args, **kwargs):
62 """
63 Launch the parsing itself.
64 """
65 ofx_file = tempfile.NamedTemporaryFile()
66 ofx_file.seek(0)
67 ofx_file.write(self.filebuffer)
68 ofx_file.flush()
69 ofx = ofxparse.OfxParser.parse(file(ofx_file.name))
70 ofx_file.close()
71 res = []
72 for transaction in ofx.account.statement.transactions:
73 res.append({
74 'date': transaction.date,
75 'amount': transaction.amount,
76 'ref': transaction.type,
77 'label': transaction.payee,
78 })
79 self.result_row_list = res
80 return True
81
82 def _validate(self, *args, **kwargs):
83 """
84 Nothing to do here. ofxparse trigger possible format errors.
85 """
86 return True
87
88 def _post(self, *args, **kwargs):
89 """
90 Nothing is needed to do after parsing.
91 """
92 return True
93
94 def _post(self, *args, **kwargs):
95 """
96 Nothing to do.
97 """
98 return True
99
100 def get_st_line_vals(self, line, *args, **kwargs):
101 """
102 This method must return a dict of vals that can be passed to create
103 method of statement line in order to record it. It is the
104 responsibility of every parser to give this dict of vals, so each one
105 can implement his own way of recording the lines.
106 :param: line: a dict of vals that represent a line of
107 result_row_list
108 :return: dict of values to give to the create method of statement
109 line
110 """
111 return {
112 'name': line.get('label', line.get('ref', '/')),
113 'date': line.get('date', datetime.datetime.now().date()),
114 'amount': line.get('amount', 0.0),
115 'ref': line.get('ref', '/'),
116 'label': line.get('label', ''),
117 }
118
0119
=== added file 'account_statement_ofx_import/statement.py'
--- account_statement_ofx_import/statement.py 1970-01-01 00:00:00 +0000
+++ account_statement_ofx_import/statement.py 2013-11-04 12:25:22 +0000
@@ -0,0 +1,46 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# Author: Pedro Manuel Baeza Romero
5# Copyright 2013 Servicios Tecnológicos Avanzados
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21from openerp.tools.translate import _
22from openerp.osv import fields, orm
23
24class AccountStatementProfil(orm.Model):
25 _inherit = "account.statement.profile"
26
27 def get_import_type_selection(self, cr, uid, context=None):
28 """
29 Inherited from parent to add parser.
30 """
31 selection = super(AccountStatementProfil, self
32 ).get_import_type_selection(cr, uid,
33 context=context)
34 selection.append(('ofx_so', _('OFX - Open Financial Exchange')))
35 return selection
36
37 _columns = {
38 'import_type': fields.selection(
39 get_import_type_selection,
40 'Type of import',
41 required=True,
42 help="Choose here the method by which you want to import bank"
43 "statement for this profile."),
44
45 }
46

Subscribers

People subscribed via source and target branches