From 731330555a4ab65bf88d408beac13efbe6a5b683 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Mon, 15 Dec 2014 10:18:55 +0100 Subject: [PATCH 01/10] [RFR] Move backported bank import modules from bank-payment to bank-statement-import repository. --- account_bank_statement_import/__init__.py | 5 + account_bank_statement_import/__openerp__.py | 25 ++++ .../account_bank_statement_import.py | 96 ++++++++++++++ .../account_bank_statement_import_view.xml | 46 +++++++ .../demo/fiscalyear_period.xml | 119 ++++++++++++++++++ .../demo/partner_bank.xml | 38 ++++++ account_bank_statement_import_ofx/__init__.py | 5 + .../__openerp__.py | 26 ++++ .../account_bank_statement_import_ofx.py | 74 +++++++++++ .../test_ofx_file/test_ofx.ofx | 100 +++++++++++++++ .../tests/__init__.py | 5 + .../tests/test_import_bank_statement.py | 30 +++++ account_bank_statement_import_qif/__init__.py | 5 + .../__openerp__.py | 27 ++++ .../account_bank_statement_import_qif.py | 75 +++++++++++ .../test_qif_file/test_qif.qif | 21 ++++ .../tests/__init__.py | 5 + .../tests/test_import_bank_statement.py | 27 ++++ 18 files changed, 729 insertions(+) create mode 100644 account_bank_statement_import/__init__.py create mode 100644 account_bank_statement_import/__openerp__.py create mode 100644 account_bank_statement_import/account_bank_statement_import.py create mode 100644 account_bank_statement_import/account_bank_statement_import_view.xml create mode 100644 account_bank_statement_import/demo/fiscalyear_period.xml create mode 100644 account_bank_statement_import/demo/partner_bank.xml create mode 100644 account_bank_statement_import_ofx/__init__.py create mode 100644 account_bank_statement_import_ofx/__openerp__.py create mode 100644 account_bank_statement_import_ofx/account_bank_statement_import_ofx.py create mode 100644 account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx create mode 100644 account_bank_statement_import_ofx/tests/__init__.py create mode 100644 account_bank_statement_import_ofx/tests/test_import_bank_statement.py create mode 100644 account_bank_statement_import_qif/__init__.py create mode 100644 account_bank_statement_import_qif/__openerp__.py create mode 100644 account_bank_statement_import_qif/account_bank_statement_import_qif.py create mode 100644 account_bank_statement_import_qif/test_qif_file/test_qif.qif create mode 100644 account_bank_statement_import_qif/tests/__init__.py create mode 100644 account_bank_statement_import_qif/tests/test_import_bank_statement.py diff --git a/account_bank_statement_import/__init__.py b/account_bank_statement_import/__init__.py new file mode 100644 index 0000000..edce853 --- /dev/null +++ b/account_bank_statement_import/__init__.py @@ -0,0 +1,5 @@ +# -*- encoding: utf-8 -*- + +import account_bank_statement_import + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import/__openerp__.py b/account_bank_statement_import/__openerp__.py new file mode 100644 index 0000000..af12dd4 --- /dev/null +++ b/account_bank_statement_import/__openerp__.py @@ -0,0 +1,25 @@ +# -*- encoding: utf-8 -*- +{ + 'name': 'Account Bank Statement Import', + 'version': '1.0', + 'author': 'OpenERP SA', + 'depends': ['account'], + 'demo': [], + 'description' : """Generic Wizard to Import Bank Statements. + + Includes the import of files in .OFX format + + Backport from Odoo 9.0 + """, + 'data' : [ + 'account_bank_statement_import_view.xml', + ], + 'demo': [ + 'demo/fiscalyear_period.xml', + 'demo/partner_bank.xml', + ], + 'auto_install': False, + 'installable': True, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import/account_bank_statement_import.py b/account_bank_statement_import/account_bank_statement_import.py new file mode 100644 index 0000000..7866aeb --- /dev/null +++ b/account_bank_statement_import/account_bank_statement_import.py @@ -0,0 +1,96 @@ +# -*- coding: utf-8 -*- + +from openerp.osv import fields, osv +from openerp.tools.translate import _ + +import logging +_logger = logging.getLogger(__name__) + +_IMPORT_FILE_TYPE = [('none', _('No Import Format Available'))] + +def add_file_type(selection_value): + global _IMPORT_FILE_TYPE + if _IMPORT_FILE_TYPE[0][0] == 'none': + _IMPORT_FILE_TYPE = [selection_value] + else: + _IMPORT_FILE_TYPE.append(selection_value) + +class account_bank_statement_import(osv.TransientModel): + _name = 'account.bank.statement.import' + _description = 'Import Bank Statement' + + def _get_import_file_type(self, cr, uid, context=None): + return _IMPORT_FILE_TYPE + + _columns = { + 'data_file': fields.binary('Bank Statement File', required=True, help='Get you bank statements in electronic format from your bank and select them here.'), + 'file_type': fields.selection(_get_import_file_type, 'File Type', required=True), + 'journal_id': fields.many2one('account.journal', 'Journal', required=True, help="The journal for which the bank statements will be created"), + } + + def _get_first_file_type(self, cr, uid, context=None): + return self._get_import_file_type(cr, uid, context=context)[0][0] + + def _get_default_journal(self, cr, uid, context=None): + company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'account.bank.statement', context=context) + journal_ids = self.pool.get('account.journal').search(cr, uid, [('type', '=', 'bank'), ('company_id', '=', company_id)], context=context) + return journal_ids and journal_ids[0] or False + + _defaults = { + 'file_type': _get_first_file_type, + 'journal_id': _get_default_journal, + } + + def _detect_partner(self, cr, uid, identifying_string, identifying_field='acc_number', context=None): + """Try to find a bank account and its related partner for the given 'identifying_string', looking on the field 'identifying_field'. + + :param identifying_string: varchar + :param identifying_field: varchar corresponding to the name of a field of res.partner.bank + :returns: tuple(ID of the bank account found or False, ID of the partner for the bank account found or False) + """ + partner_id = False + bank_account_id = False + if identifying_string: + ids = self.pool.get('res.partner.bank').search(cr, uid, [(identifying_field, '=', identifying_string)], context=context) + if ids: + bank_account_id = ids[0] + partner_id = self.pool.get('res.partner.bank').browse(cr, uid, bank_account_id, context=context).partner_id.id + else: + #create the bank account, not linked to any partner. The reconciliation will link the partner manually + #chosen at the bank statement final confirmation time. + try: + type_model, type_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'base', 'bank_normal') + type_id = self.pool.get('res.partner.bank.type').browse(cr, uid, type_id, context=context) + bank_code = type_id.code + except ValueError: + bank_code = 'bank' + acc_number = identifying_field == 'acc_number' and identifying_string or _('Undefined') + bank_account_vals = { + 'acc_number': acc_number, + 'state': bank_code, + } + bank_account_vals[identifying_field] = identifying_string + bank_account_id = self.pool.get('res.partner.bank').create(cr, uid, bank_account_vals, context=context) + return bank_account_id, partner_id + + def import_bank_statement(self, cr, uid, bank_statement_vals=False, context=None): + """ Get a list of values to pass to the create() of account.bank.statement object, and returns a list of ID created using those values""" + statement_ids = [] + for vals in bank_statement_vals: + statement_ids.append(self.pool.get('account.bank.statement').create(cr, uid, vals, context=context)) + return statement_ids + + def process_none(self, cr, uid, data_file, journal_id=False, context=None): + raise osv.except_osv(_('Error'), _('No available format for importing bank statement. You can install one of the file format available through the module installation.')) + + def parse_file(self, cr, uid, ids, context=None): + """ Process the file chosen in the wizard and returns a list view of the imported bank statements""" + data = self.browse(cr, uid, ids[0], context=context) + vals = getattr(self, "process_%s" % data.file_type)(cr, uid, data.data_file, data.journal_id.id, context=context) + statement_ids = self.import_bank_statement(cr, uid, vals, context=context) + model, action_id = self.pool.get('ir.model.data').get_object_reference(cr, uid, 'account', 'action_bank_statement_tree') + action = self.pool[model].read(cr, uid, action_id, context=context) + action['domain'] = "[('id', 'in', [" + ', '.join(map(str, statement_ids)) + "])]" + return action + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import/account_bank_statement_import_view.xml b/account_bank_statement_import/account_bank_statement_import_view.xml new file mode 100644 index 0000000..c48371c --- /dev/null +++ b/account_bank_statement_import/account_bank_statement_import_view.xml @@ -0,0 +1,46 @@ + + + + + + Import Bank Statements + account.bank.statement.import + 1 + +
+ + + + + + + + How to import your bank statement in OpenERP. + + +
+
+
+
+
+ + + Import + ir.actions.act_window + account.bank.statement.import + form + form + new + + + + + +
+
diff --git a/account_bank_statement_import/demo/fiscalyear_period.xml b/account_bank_statement_import/demo/fiscalyear_period.xml new file mode 100644 index 0000000..41b4be3 --- /dev/null +++ b/account_bank_statement_import/demo/fiscalyear_period.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/account_bank_statement_import/demo/partner_bank.xml b/account_bank_statement_import/demo/partner_bank.xml new file mode 100644 index 0000000..47e8fa7 --- /dev/null +++ b/account_bank_statement_import/demo/partner_bank.xml @@ -0,0 +1,38 @@ + + + + + + Agrolait + 00987654321 + + bank + + + + + China Export + 00987654322 + + bank + + + + + Delta PC + 10987654320 + + bank + + + + + Epic Technologies + 10987654322 + + bank + + + + + diff --git a/account_bank_statement_import_ofx/__init__.py b/account_bank_statement_import_ofx/__init__.py new file mode 100644 index 0000000..fe838c2 --- /dev/null +++ b/account_bank_statement_import_ofx/__init__.py @@ -0,0 +1,5 @@ +# -*- encoding: utf-8 -*- + +import account_bank_statement_import_ofx + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import_ofx/__openerp__.py b/account_bank_statement_import_ofx/__openerp__.py new file mode 100644 index 0000000..8cd569b --- /dev/null +++ b/account_bank_statement_import_ofx/__openerp__.py @@ -0,0 +1,26 @@ +# -*- encoding: utf-8 -*- +{ + 'name': 'Import OFX Bank Statement', + 'version': '1.0', + 'author': 'OpenERP SA', + 'depends': ['account_bank_statement_import'], + 'demo': [], + 'description' : """ +Module to import OFX bank statements. +====================================== + +This module allows you to import the machine readable OFX Files in Odoo: they are parsed and stored in human readable format in +Accounting \ Bank and Cash \ Bank Statements. + +Bank Statements may be generated containing a subset of the OFX information (only those transaction lines that are required for the +creation of the Financial Accounting records). + +Backported from Odoo 9.0 + """, + 'data' : [], + 'demo': [], + 'auto_install': False, + 'installable': True, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py new file mode 100644 index 0000000..13966c0 --- /dev/null +++ b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py @@ -0,0 +1,74 @@ +# -*- coding: utf-8 -*- + +import logging +import base64 +import os + +from openerp.osv import osv +from openerp.tools.translate import _ + +_logger = logging.getLogger(__name__) + +from openerp.addons.account_bank_statement_import import account_bank_statement_import as ibs +ibs.add_file_type(('ofx', 'OFX')) + +try: + from ofxparse import OfxParser as ofxparser +except ImportError: + _logger.warning("OFX parser unavailable because the `ofxparse` Python library cannot be found." + "It can be downloaded and installed from `https://pypi.python.org/pypi/ofxparse`.") + ofxparser = None + +class account_bank_statement_import(osv.TransientModel): + _inherit = 'account.bank.statement.import' + + def process_ofx(self, cr, uid, data_file, journal_id=False, context=None): + """ Import a file in the .OFX format""" + if ofxparser is None: + raise osv.except_osv(_("Error"), _("OFX parser unavailable because the `ofxparse` Python library cannot be found." + "It can be downloaded and installed from `https://pypi.python.org/pypi/ofxparse`.")) + try: + tempfile = open("temp.ofx", "w+") + tempfile.write(base64.decodestring(data_file)) + tempfile.read() + pathname = os.path.dirname('temp.ofx') + path = os.path.join(os.path.abspath(pathname), 'temp.ofx') + ofx = ofxparser.parse(file(path)) + except: + raise osv.except_osv(_('Import Error!'), _('Please check OFX file format is proper or not.')) + line_ids = [] + total_amt = 0.00 + try: + for transaction in ofx.account.statement.transactions: + bank_account_id, partner_id = self._detect_partner(cr, uid, transaction.payee, identifying_field='owner_name', context=context) + vals_line = { + 'date': transaction.date, + 'name': transaction.payee + ': ' + transaction.memo, + 'ref': transaction.id, + 'amount': transaction.amount, + 'partner_id': partner_id, + 'bank_account_id': bank_account_id, + } + total_amt += float(transaction.amount) + line_ids.append((0, 0, vals_line)) + except Exception, e: + raise osv.except_osv(_('Error!'), _("Following problem has been occurred while importing your file, Please verify the file is proper or not.\n\n %s" % e.message)) + st_start_date = ofx.account.statement.start_date or False + st_end_date = ofx.account.statement.end_date or False + period_obj = self.pool.get('account.period') + if st_end_date: + period_ids = period_obj.find(cr, uid, st_end_date, context=context) + else: + period_ids = period_obj.find(cr, uid, st_start_date, context=context) + vals_bank_statement = { + 'name': ofx.account.routing_number, + 'balance_start': ofx.account.statement.balance, + 'balance_end_real': float(ofx.account.statement.balance) + total_amt, + 'period_id': period_ids and period_ids[0] or False, + 'journal_id': journal_id + } + vals_bank_statement.update({'line_ids': line_ids}) + os.remove(path) + return [vals_bank_statement] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx b/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx new file mode 100644 index 0000000..37df4d0 --- /dev/null +++ b/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx @@ -0,0 +1,100 @@ + + + + + + + 0 + INFO + + 20130831165153.000[-8:PST] + ENG + + + + + 0 + + 0 + INFO + + + USD + + 000000123 + 123456 + CHECKING + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -80 + 219378 + Agrolait + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -90 + 219379 + China Export + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -100 + 219380 + Axelor Scuba + + + + 20130801 + 20130831165153.000[-8:PST] + + POS + 20130824080000 + -90 + 219381 + China Scuba + + + + 2156.56 + 20130831165153 + + + + + + + 0 + + 0 + INFO + + + USD + + 123412341234 + + + + + -562.00 + 20130831165153 + + + + + diff --git a/account_bank_statement_import_ofx/tests/__init__.py b/account_bank_statement_import_ofx/tests/__init__.py new file mode 100644 index 0000000..8a5a8e9 --- /dev/null +++ b/account_bank_statement_import_ofx/tests/__init__.py @@ -0,0 +1,5 @@ +from . import test_import_bank_statement + +checks = [ + test_import_bank_statement +] diff --git a/account_bank_statement_import_ofx/tests/test_import_bank_statement.py b/account_bank_statement_import_ofx/tests/test_import_bank_statement.py new file mode 100644 index 0000000..967d647 --- /dev/null +++ b/account_bank_statement_import_ofx/tests/test_import_bank_statement.py @@ -0,0 +1,30 @@ +from openerp.tests.common import TransactionCase +from openerp.modules.module import get_module_resource + +class TestOfxFile(TransactionCase): + """Tests for import bank statement ofx file format (account.bank.statement.import) + """ + + def setUp(self): + super(TestOfxFile, self).setUp() + self.statement_import_model = self.registry('account.bank.statement.import') + self.bank_statement_model = self.registry('account.bank.statement') + + def test_ofx_file_import(self): + try: + from ofxparse import OfxParser as ofxparser + except ImportError: + #the Python library isn't installed on the server, the OFX import is unavailable and the test cannot be run + return True + cr, uid = self.cr, self.uid + ofx_file_path = get_module_resource('account_bank_statement_import_ofx', 'test_ofx_file', 'test_ofx.ofx') + ofx_file = open(ofx_file_path, 'rb').read().encode('base64') + bank_statement_id = self.statement_import_model.create(cr, uid, dict( + file_type='ofx', + data_file=ofx_file, + )) + self.statement_import_model.parse_file(cr, uid, [bank_statement_id]) + statement_id = self.bank_statement_model.search(cr, uid, [('name', '=', '000000123')])[0] + bank_st_record = self.bank_statement_model.browse(cr, uid, statement_id) + self.assertEquals(bank_st_record.balance_start, 2156.56) + self.assertEquals(bank_st_record.balance_end_real, 1796.56) diff --git a/account_bank_statement_import_qif/__init__.py b/account_bank_statement_import_qif/__init__.py new file mode 100644 index 0000000..befbd0e --- /dev/null +++ b/account_bank_statement_import_qif/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- + +import account_bank_statement_import_qif + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import_qif/__openerp__.py b/account_bank_statement_import_qif/__openerp__.py new file mode 100644 index 0000000..3fe1eb2 --- /dev/null +++ b/account_bank_statement_import_qif/__openerp__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- + +{ + 'name': 'Import QIF Bank Statement', + 'version': '1.0', + 'author': 'OpenERP SA', + 'description': ''' +Module to import QIF bank statements. +====================================== + +This module allows you to import the machine readable QIF Files in Odoo: they are parsed and stored in human readable format in +Accounting \ Bank and Cash \ Bank Statements. + +Bank Statements may be generated containing a subset of the QIF information (only those transaction lines that are required for the +creation of the Financial Accounting records). + +Backported from Odoo 9.0 +''', + 'images' : [], + 'depends': ['account_bank_statement_import'], + 'demo': [], + 'data': [], + 'auto_install': False, + 'installable': True, +} + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import_qif/account_bank_statement_import_qif.py b/account_bank_statement_import_qif/account_bank_statement_import_qif.py new file mode 100644 index 0000000..a253cb6 --- /dev/null +++ b/account_bank_statement_import_qif/account_bank_statement_import_qif.py @@ -0,0 +1,75 @@ +# -*- coding: utf-8 -*- + +import dateutil.parser +import base64 +from tempfile import TemporaryFile + +from openerp.tools.translate import _ +from openerp.osv import osv + +from openerp.addons.account_bank_statement_import import account_bank_statement_import as ibs + +ibs.add_file_type(('qif', 'QIF')) + +class account_bank_statement_import(osv.TransientModel): + _inherit = "account.bank.statement.import" + + def process_qif(self, cr, uid, data_file, journal_id=False, context=None): + """ Import a file in the .QIF format""" + try: + fileobj = TemporaryFile('wb+') + fileobj.write(base64.b64decode(data_file)) + fileobj.seek(0) + file_data = "" + for line in fileobj.readlines(): + file_data += line + fileobj.close() + if '\r' in file_data: + data_list = file_data.split('\r') + else: + data_list = file_data.split('\n') + header = data_list[0].strip() + header = header.split(":")[1] + except: + raise osv.except_osv(_('Import Error!'), _('Please check QIF file format is proper or not.')) + line_ids = [] + vals_line = {} + total = 0 + if header == "Bank": + vals_bank_statement = {} + for line in data_list: + line = line.strip() + if not line: + continue + if line[0] == 'D': # date of transaction + vals_line['date'] = dateutil.parser.parse(line[1:], fuzzy=True).date() + if vals_line.get('date') and not vals_bank_statement.get('period_id'): + period_ids = self.pool.get('account.period').find(cr, uid, vals_line['date'], context=context) + vals_bank_statement.update({'period_id': period_ids and period_ids[0] or False}) + elif line[0] == 'T': # Total amount + total += float(line[1:].replace(',', '')) + vals_line['amount'] = float(line[1:].replace(',', '')) + elif line[0] == 'N': # Check number + vals_line['ref'] = line[1:] + elif line[0] == 'P': # Payee + bank_account_id, partner_id = self._detect_partner(cr, uid, line[1:], identifying_field='owner_name', context=context) + vals_line['partner_id'] = partner_id + vals_line['bank_account_id'] = bank_account_id + vals_line['name'] = 'name' in vals_line and line[1:] + ': ' + vals_line['name'] or line[1:] + elif line[0] == 'M': # Memo + vals_line['name'] = 'name' in vals_line and vals_line['name'] + ': ' + line[1:] or line[1:] + elif line[0] == '^': # end of item + line_ids.append((0, 0, vals_line)) + vals_line = {} + elif line[0] == '\n': + line_ids = [] + else: + pass + else: + raise osv.except_osv(_('Error!'), _('Cannot support this Format !Type:%s.') % (header,)) + vals_bank_statement.update({'balance_end_real': total, + 'line_ids': line_ids, + 'journal_id': journal_id}) + return [vals_bank_statement] + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import_qif/test_qif_file/test_qif.qif b/account_bank_statement_import_qif/test_qif_file/test_qif.qif new file mode 100644 index 0000000..5388e6d --- /dev/null +++ b/account_bank_statement_import_qif/test_qif_file/test_qif.qif @@ -0,0 +1,21 @@ +!Type:Bank +D8/12/13 +T-1,000.00 +PDelta PC +^ +D8/15/13 +T-75.46 +PWalts Drugs +^ +D3/3/13 +T-379.00 +PEpic Technologies +^ +D3/4/13 +T-20.28 +PYOUR LOCAL SUPERMARKET +^ +D3/3/13 +T-421.35 +PSPRINGFIELD WATER UTILITY +^ diff --git a/account_bank_statement_import_qif/tests/__init__.py b/account_bank_statement_import_qif/tests/__init__.py new file mode 100644 index 0000000..05b23c4 --- /dev/null +++ b/account_bank_statement_import_qif/tests/__init__.py @@ -0,0 +1,5 @@ +from . import test_import_bank_statement +checks = [ + test_import_bank_statement +] + diff --git a/account_bank_statement_import_qif/tests/test_import_bank_statement.py b/account_bank_statement_import_qif/tests/test_import_bank_statement.py new file mode 100644 index 0000000..0f9ef4d --- /dev/null +++ b/account_bank_statement_import_qif/tests/test_import_bank_statement.py @@ -0,0 +1,27 @@ +from openerp.tests.common import TransactionCase +from openerp.modules.module import get_module_resource + +class TestQifFile(TransactionCase): + """Tests for import bank statement qif file format (account.bank.statement.import) + """ + + def setUp(self): + super(TestQifFile, self).setUp() + self.statement_import_model = self.registry('account.bank.statement.import') + self.bank_statement_model = self.registry('account.bank.statement') + self.bank_statement_line_model = self.registry('account.bank.statement.line') + + def test_qif_file_import(self): + from openerp.tools import float_compare + cr, uid = self.cr, self.uid + qif_file_path = get_module_resource('account_bank_statement_import_qif', 'test_qif_file', 'test_qif.qif') + qif_file = open(qif_file_path, 'rb').read().encode('base64') + bank_statement_id = self.statement_import_model.create(cr, uid, dict( + file_type='qif', + data_file=qif_file, + )) + self.statement_import_model.parse_file(cr, uid, [bank_statement_id]) + line_id = self.bank_statement_line_model.search(cr, uid, [('name', '=', 'YOUR LOCAL SUPERMARKET')])[0] + statement_id = self.bank_statement_line_model.browse(cr, uid, line_id).statement_id.id + bank_st_record = self.bank_statement_model.browse(cr, uid, statement_id) + assert float_compare(bank_st_record.balance_end_real, -1896.09, 2) == 0 From 13f32e2e62f02e944e9aaf6bebebea8809ae70b7 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Mon, 15 Dec 2014 12:00:52 +0100 Subject: [PATCH 02/10] [FIX] Change year in test files to 2014 [FIX] Change reference to not existing menu --- .../account_bank_statement_import_view.xml | 7 ++++- .../test_ofx_file/test_ofx.ofx | 30 +++++++++---------- .../test_qif_file/test_qif.qif | 10 +++---- 3 files changed, 26 insertions(+), 21 deletions(-) diff --git a/account_bank_statement_import/account_bank_statement_import_view.xml b/account_bank_statement_import/account_bank_statement_import_view.xml index c48371c..f375f4a 100644 --- a/account_bank_statement_import/account_bank_statement_import_view.xml +++ b/account_bank_statement_import/account_bank_statement_import_view.xml @@ -40,7 +40,12 @@ - + diff --git a/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx b/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx index 37df4d0..a1bf391 100644 --- a/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx +++ b/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx @@ -7,7 +7,7 @@ 0 INFO - 20130831165153.000[-8:PST] + 20140831165153.000[-8:PST] ENG @@ -26,44 +26,44 @@ CHECKING - 20130801 - 20130831165153.000[-8:PST] + 20140801 + 20140831165153.000[-8:PST] POS - 20130824080000 + 20140824080000 -80 219378 Agrolait - 20130801 - 20130831165153.000[-8:PST] + 20140801 + 20140831165153.000[-8:PST] POS - 20130824080000 + 20140824080000 -90 219379 China Export - 20130801 - 20130831165153.000[-8:PST] + 20140801 + 20140831165153.000[-8:PST] POS - 20130824080000 + 20140824080000 -100 219380 Axelor Scuba - 20130801 - 20130831165153.000[-8:PST] + 20140801 + 20140831165153.000[-8:PST] POS - 20130824080000 + 20140824080000 -90 219381 China Scuba @@ -71,7 +71,7 @@ 2156.56 - 20130831165153 + 20140831165153 @@ -92,7 +92,7 @@ -562.00 - 20130831165153 + 20140831165153 diff --git a/account_bank_statement_import_qif/test_qif_file/test_qif.qif b/account_bank_statement_import_qif/test_qif_file/test_qif.qif index 5388e6d..8eb1b61 100644 --- a/account_bank_statement_import_qif/test_qif_file/test_qif.qif +++ b/account_bank_statement_import_qif/test_qif_file/test_qif.qif @@ -1,21 +1,21 @@ !Type:Bank -D8/12/13 +D8/12/14 T-1,000.00 PDelta PC ^ -D8/15/13 +D8/15/14 T-75.46 PWalts Drugs ^ -D3/3/13 +D3/3/14 T-379.00 PEpic Technologies ^ -D3/4/13 +D3/4/14 T-20.28 PYOUR LOCAL SUPERMARKET ^ -D3/3/13 +D3/3/14 T-421.35 PSPRINGFIELD WATER UTILITY ^ From d78e49cc1d11bc463ae3444e787cc8ad5e1567fd Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Mon, 15 Dec 2014 12:37:19 +0100 Subject: [PATCH 03/10] [FIX] Add noqa tags to backported py files. --- account_bank_statement_import/account_bank_statement_import.py | 2 ++ .../account_bank_statement_import_ofx.py | 2 ++ .../tests/test_import_bank_statement.py | 3 +++ .../account_bank_statement_import_qif.py | 2 ++ .../tests/test_import_bank_statement.py | 3 +++ 5 files changed, 12 insertions(+) diff --git a/account_bank_statement_import/account_bank_statement_import.py b/account_bank_statement_import/account_bank_statement_import.py index 7866aeb..d12b65e 100644 --- a/account_bank_statement_import/account_bank_statement_import.py +++ b/account_bank_statement_import/account_bank_statement_import.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa from openerp.osv import fields, osv from openerp.tools.translate import _ diff --git a/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py index 13966c0..6f690a7 100644 --- a/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py +++ b/account_bank_statement_import_ofx/account_bank_statement_import_ofx.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa import logging import base64 diff --git a/account_bank_statement_import_ofx/tests/test_import_bank_statement.py b/account_bank_statement_import_ofx/tests/test_import_bank_statement.py index 967d647..f804f90 100644 --- a/account_bank_statement_import_ofx/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_ofx/tests/test_import_bank_statement.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa from openerp.tests.common import TransactionCase from openerp.modules.module import get_module_resource diff --git a/account_bank_statement_import_qif/account_bank_statement_import_qif.py b/account_bank_statement_import_qif/account_bank_statement_import_qif.py index a253cb6..a95656e 100644 --- a/account_bank_statement_import_qif/account_bank_statement_import_qif.py +++ b/account_bank_statement_import_qif/account_bank_statement_import_qif.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa import dateutil.parser import base64 diff --git a/account_bank_statement_import_qif/tests/test_import_bank_statement.py b/account_bank_statement_import_qif/tests/test_import_bank_statement.py index 0f9ef4d..6838129 100644 --- a/account_bank_statement_import_qif/tests/test_import_bank_statement.py +++ b/account_bank_statement_import_qif/tests/test_import_bank_statement.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa from openerp.tests.common import TransactionCase from openerp.modules.module import get_module_resource From 7a8c2808df2f07ade2e902dfbb0e3e7cc331151c Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Mon, 15 Dec 2014 12:51:26 +0100 Subject: [PATCH 04/10] [FIX] Change menu option to more clearly show that import applies to bank statements (this was in the original diff from Alexis de Lattre, but strangely missing from the moved import module). --- .../account_bank_statement_import_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/account_bank_statement_import/account_bank_statement_import_view.xml b/account_bank_statement_import/account_bank_statement_import_view.xml index f375f4a..246601f 100644 --- a/account_bank_statement_import/account_bank_statement_import_view.xml +++ b/account_bank_statement_import/account_bank_statement_import_view.xml @@ -31,7 +31,7 @@ - Import + Import Bank Statement ir.actions.act_window account.bank.statement.import form From 44240a39ab62639f3a632568c33f6b2264827d3d Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Mon, 15 Dec 2014 12:59:11 +0100 Subject: [PATCH 05/10] [FIX] Reverse change of year 2013 to 2014 in test files, and add warning to module descriptions that periods in 2013 should exist when using test-files. --- .../__openerp__.py | 4 +++ .../test_ofx_file/test_ofx.ofx | 30 +++++++++---------- .../__openerp__.py | 4 +++ .../test_qif_file/test_qif.qif | 10 +++---- 4 files changed, 28 insertions(+), 20 deletions(-) diff --git a/account_bank_statement_import_ofx/__openerp__.py b/account_bank_statement_import_ofx/__openerp__.py index 8cd569b..8142901 100644 --- a/account_bank_statement_import_ofx/__openerp__.py +++ b/account_bank_statement_import_ofx/__openerp__.py @@ -16,6 +16,10 @@ Bank Statements may be generated containing a subset of the OFX information (onl creation of the Financial Accounting records). Backported from Odoo 9.0 + +When testing with the provided test file, make sure the demo data from the +base account_bank_statement_import module has been imported, or manually +create periods for the year 2013. """, 'data' : [], 'demo': [], diff --git a/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx b/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx index a1bf391..37df4d0 100644 --- a/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx +++ b/account_bank_statement_import_ofx/test_ofx_file/test_ofx.ofx @@ -7,7 +7,7 @@ 0 INFO - 20140831165153.000[-8:PST] + 20130831165153.000[-8:PST] ENG @@ -26,44 +26,44 @@ CHECKING - 20140801 - 20140831165153.000[-8:PST] + 20130801 + 20130831165153.000[-8:PST] POS - 20140824080000 + 20130824080000 -80 219378 Agrolait - 20140801 - 20140831165153.000[-8:PST] + 20130801 + 20130831165153.000[-8:PST] POS - 20140824080000 + 20130824080000 -90 219379 China Export - 20140801 - 20140831165153.000[-8:PST] + 20130801 + 20130831165153.000[-8:PST] POS - 20140824080000 + 20130824080000 -100 219380 Axelor Scuba - 20140801 - 20140831165153.000[-8:PST] + 20130801 + 20130831165153.000[-8:PST] POS - 20140824080000 + 20130824080000 -90 219381 China Scuba @@ -71,7 +71,7 @@ 2156.56 - 20140831165153 + 20130831165153 @@ -92,7 +92,7 @@ -562.00 - 20140831165153 + 20130831165153 diff --git a/account_bank_statement_import_qif/__openerp__.py b/account_bank_statement_import_qif/__openerp__.py index 3fe1eb2..499e10e 100644 --- a/account_bank_statement_import_qif/__openerp__.py +++ b/account_bank_statement_import_qif/__openerp__.py @@ -15,6 +15,10 @@ Bank Statements may be generated containing a subset of the QIF information (onl creation of the Financial Accounting records). Backported from Odoo 9.0 + +When testing with the provided test file, make sure the demo data from the +base account_bank_statement_import module has been imported, or manually +create periods for the year 2013. ''', 'images' : [], 'depends': ['account_bank_statement_import'], diff --git a/account_bank_statement_import_qif/test_qif_file/test_qif.qif b/account_bank_statement_import_qif/test_qif_file/test_qif.qif index 8eb1b61..5388e6d 100644 --- a/account_bank_statement_import_qif/test_qif_file/test_qif.qif +++ b/account_bank_statement_import_qif/test_qif_file/test_qif.qif @@ -1,21 +1,21 @@ !Type:Bank -D8/12/14 +D8/12/13 T-1,000.00 PDelta PC ^ -D8/15/14 +D8/15/13 T-75.46 PWalts Drugs ^ -D3/3/14 +D3/3/13 T-379.00 PEpic Technologies ^ -D3/4/14 +D3/4/13 T-20.28 PYOUR LOCAL SUPERMARKET ^ -D3/3/14 +D3/3/13 T-421.35 PSPRINGFIELD WATER UTILITY ^ From 1a11907f0b2a44a0c19e23f74cb53e5e03f9044c Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Mon, 15 Dec 2014 13:48:57 +0100 Subject: [PATCH 06/10] [TST] Add install of ofxparse to .travis.yml to reenable build test. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index efbe300..2d23516 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ virtualenv: install: - git clone https://github.com/OCA/maintainer-quality-tools.git ${HOME}/maintainer-quality-tools - export PATH=${HOME}/maintainer-quality-tools/travis:${PATH} + - pip install ofxparse - travis_install_nightly # example: dependency # - git clone https://github.com/OCA/webkit-tools -b ${VERSION} $HOME/webkit-tools From e0d24ac1ff005adbc60af7c7f2668bbd47849d46 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Mon, 15 Dec 2014 14:07:54 +0100 Subject: [PATCH 07/10] [FIX] Apparently noqa tag should also be part of __openerp__.py files. --- account_bank_statement_import/__openerp__.py | 2 ++ account_bank_statement_import_ofx/__openerp__.py | 2 ++ account_bank_statement_import_qif/__openerp__.py | 3 ++- 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/account_bank_statement_import/__openerp__.py b/account_bank_statement_import/__openerp__.py index af12dd4..9dfc61d 100644 --- a/account_bank_statement_import/__openerp__.py +++ b/account_bank_statement_import/__openerp__.py @@ -1,4 +1,6 @@ # -*- encoding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa { 'name': 'Account Bank Statement Import', 'version': '1.0', diff --git a/account_bank_statement_import_ofx/__openerp__.py b/account_bank_statement_import_ofx/__openerp__.py index 8142901..25056dd 100644 --- a/account_bank_statement_import_ofx/__openerp__.py +++ b/account_bank_statement_import_ofx/__openerp__.py @@ -1,4 +1,6 @@ # -*- encoding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa { 'name': 'Import OFX Bank Statement', 'version': '1.0', diff --git a/account_bank_statement_import_qif/__openerp__.py b/account_bank_statement_import_qif/__openerp__.py index 499e10e..d06c90a 100644 --- a/account_bank_statement_import_qif/__openerp__.py +++ b/account_bank_statement_import_qif/__openerp__.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- - +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa { 'name': 'Import QIF Bank Statement', 'version': '1.0', From 2ebba0ee05c7fc2e9c98f6a9ca1077e5b79d9c90 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Sun, 21 Dec 2014 13:41:43 +0100 Subject: [PATCH 08/10] [FIX] Add noqa even to __init__.py files. --- account_bank_statement_import/__init__.py | 2 ++ account_bank_statement_import_ofx/__init__.py | 2 ++ account_bank_statement_import_ofx/tests/__init__.py | 3 +++ account_bank_statement_import_qif/__init__.py | 2 ++ account_bank_statement_import_qif/tests/__init__.py | 3 +++ 5 files changed, 12 insertions(+) diff --git a/account_bank_statement_import/__init__.py b/account_bank_statement_import/__init__.py index edce853..75e43fd 100644 --- a/account_bank_statement_import/__init__.py +++ b/account_bank_statement_import/__init__.py @@ -1,4 +1,6 @@ # -*- encoding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa import account_bank_statement_import diff --git a/account_bank_statement_import_ofx/__init__.py b/account_bank_statement_import_ofx/__init__.py index fe838c2..146530c 100644 --- a/account_bank_statement_import_ofx/__init__.py +++ b/account_bank_statement_import_ofx/__init__.py @@ -1,4 +1,6 @@ # -*- encoding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa import account_bank_statement_import_ofx diff --git a/account_bank_statement_import_ofx/tests/__init__.py b/account_bank_statement_import_ofx/tests/__init__.py index 8a5a8e9..fa3fb30 100644 --- a/account_bank_statement_import_ofx/tests/__init__.py +++ b/account_bank_statement_import_ofx/tests/__init__.py @@ -1,3 +1,6 @@ +# -*- encoding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa from . import test_import_bank_statement checks = [ diff --git a/account_bank_statement_import_qif/__init__.py b/account_bank_statement_import_qif/__init__.py index befbd0e..79da9b5 100644 --- a/account_bank_statement_import_qif/__init__.py +++ b/account_bank_statement_import_qif/__init__.py @@ -1,4 +1,6 @@ # -*- coding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa import account_bank_statement_import_qif diff --git a/account_bank_statement_import_qif/tests/__init__.py b/account_bank_statement_import_qif/tests/__init__.py index 05b23c4..389df58 100644 --- a/account_bank_statement_import_qif/tests/__init__.py +++ b/account_bank_statement_import_qif/tests/__init__.py @@ -1,3 +1,6 @@ +# -*- coding: utf-8 -*- +# noqa: This is a backport from Odoo. OCA has no control over style here. +# flake8: noqa from . import test_import_bank_statement checks = [ test_import_bank_statement From 4b4b8da48abe7900fe140de4f8dd32693ac605d9 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Sun, 21 Dec 2014 13:58:53 +0100 Subject: [PATCH 09/10] [FIX] Add relative imports to __init__.py files and remove #noqa, because pylint in travis is not satisfied with #noqa. --- account_bank_statement_import_qif/__init__.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/account_bank_statement_import_qif/__init__.py b/account_bank_statement_import_qif/__init__.py index 79da9b5..784a476 100644 --- a/account_bank_statement_import_qif/__init__.py +++ b/account_bank_statement_import_qif/__init__.py @@ -1,7 +1,4 @@ # -*- coding: utf-8 -*- -# noqa: This is a backport from Odoo. OCA has no control over style here. -# flake8: noqa - -import account_bank_statement_import_qif +from . import account_bank_statement_import_qif # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: From c9cbcac6cf0635b092d55550cbb0602eea79d1f1 Mon Sep 17 00:00:00 2001 From: "Ronald Portier (Therp BV)" Date: Sun, 21 Dec 2014 14:20:09 +0100 Subject: [PATCH 10/10] [FIX] Forgot to commit some __Init__.py files. --- account_bank_statement_import/__init__.py | 5 +---- account_bank_statement_import_ofx/__init__.py | 5 +---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/account_bank_statement_import/__init__.py b/account_bank_statement_import/__init__.py index 75e43fd..70262b2 100644 --- a/account_bank_statement_import/__init__.py +++ b/account_bank_statement_import/__init__.py @@ -1,7 +1,4 @@ # -*- encoding: utf-8 -*- -# noqa: This is a backport from Odoo. OCA has no control over style here. -# flake8: noqa - -import account_bank_statement_import +from . import account_bank_statement_import # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: diff --git a/account_bank_statement_import_ofx/__init__.py b/account_bank_statement_import_ofx/__init__.py index 146530c..44bd24d 100644 --- a/account_bank_statement_import_ofx/__init__.py +++ b/account_bank_statement_import_ofx/__init__.py @@ -1,7 +1,4 @@ # -*- encoding: utf-8 -*- -# noqa: This is a backport from Odoo. OCA has no control over style here. -# flake8: noqa - -import account_bank_statement_import_ofx +from . import account_bank_statement_import_ofx # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: