Browse Source
Merge pull request #125 from onesteinbv/10_mig_account_bank_statement_import_mt940_base
Merge pull request #125 from onesteinbv/10_mig_account_bank_statement_import_mt940_base
[MIG][10.0] account_bank_statement_import_mt940_base: migration to 10.0pull/155/head
Pedro M. Baeza
7 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 567 additions and 113 deletions
-
24account_bank_statement_import_mt940_base/README.rst
-
24account_bank_statement_import_mt940_base/__manifest__.py
-
212account_bank_statement_import_mt940_base/mt940.py
-
61account_bank_statement_import_mt940_base/test_files/test-ing.940
-
29account_bank_statement_import_mt940_base/test_files/test-rabo.swi
-
78account_bank_statement_import_mt940_base/test_files/test-sns.940
-
11account_bank_statement_import_mt940_base/test_files/test-wrong-file.940
-
1account_bank_statement_import_mt940_base/tests/__init__.py
-
240account_bank_statement_import_mt940_base/tests/test_import_bank_statement.py
@ -0,0 +1,61 @@ |
|||
{1:F01INGBNL2ABXXX0000000000} |
|||
{2:I940INGBNL2AXXXN} |
|||
{4: |
|||
:20:P140220000000001 |
|||
:25:NL77INGB0574908765EUR |
|||
:28C:0000 |
|||
0 |
|||
:60F:C140219EUR662,23 |
|||
:61:1402200220C1,56NTRFEREF//00000000001 |
|||
005 |
|||
/TRCD/00100/ |
|||
:86:/EREF/EV12341REP1231456T1234//CNTP/NL32INGB0000012345/INGBNL2 |
|||
A/ING BANK NV INZAKE WEB///REMI/USTD//EV10001REP1000000T1000/ |
|||
:61:1402200220D1,57NTRFPREF//00000000001006 |
|||
/TRCD/00200/ |
|||
:86:/PREF/M000000003333333//REMI/USTD//TOTAAL 1 VZ/ |
|||
:61:1402200220C1,57NRTIEREF//00000000001007 |
|||
/TRCD/00190/ |
|||
:86:/RTRN/MS03//EREF/20120123456789//CNTP/NL32INGB0000012345/INGB |
|||
NL2A/J.Janssen///REMI/USTD//Factuurnr 123456 Klantnr 00123/ |
|||
:61:1402200220D1,14NDDTEREF//00000000001009 |
|||
/TRCD/010 |
|||
16 |
|||
/ |
|||
:86:/EREF/EV123R |
|||
EP123412T1234//MARF/MND |
|||
- |
|||
EV01//CSID/NL32ZZZ9999999 |
|||
91234//CNTP/NL32INGB0000012345/INGBNL2A/ING Bank N.V. inzake WeB/ |
|||
//REMI/USTD//EV123REP123412T1234/ |
|||
:61:1402200220C1,45NDDTPREF//00000000001008 |
|||
/TRCD/01000/ |
|||
:86:/PREF/M000000001111111/ |
|||
/CSID/ |
|||
NL32ZZZ999999991234 |
|||
/ |
|||
/REMI/USTD// |
|||
TOTAAL 1 POSTEN/ |
|||
:61:1402200220D12,75NRTIEREF//00000000001010 |
|||
/TRCD/01315/ |
|||
:86:/RTRN/MS03//EREF/20120501P0123478//MARF/MND |
|||
- |
|||
120123//CSID/NL32 |
|||
ZZZ999999991234//CNTP/NL32INGB0000012345/INGBNL2A/J.Janssen///REM |
|||
I/USTD//CO |
|||
NTRIBUTIE FEB 2014/ |
|||
:61:1402200220C32,00NTRF9001123412341234//00000000001011 |
|||
/TRCD/00108/ |
|||
:86:/EREF/15814016000676480//CNTP/NL32INGB0000012345/INGBNL2A/J.J |
|||
anssen///REMI/STRD/CUR/9001123412341234/ |
|||
:61:1402200220D119,00NTRF1070123412341234//00000000001012 |
|||
/ |
|||
TRCD/00108/ |
|||
:86:/EREF/15614016000384600//CNTP/NL32INGB0000012345/INGBNL2A/ING |
|||
BANK NV///REMI/STRD/CUR/1070123412341234/ |
|||
:62F:C140220EUR564,35 |
|||
:64:C140220EUR564,35 |
|||
:65:C140221EUR564,35 |
|||
:65:C140224EUR564,35 |
|||
:86:/SUM/4/4/134,46/36,58/ |
|||
-} |
@ -0,0 +1,29 @@ |
|||
:940: |
|||
:20:940S140102 |
|||
:25:NL34RABO0142623393 EUR |
|||
:28C:0 |
|||
:60F:C131231EUR000000004433,52 |
|||
:61:140102C000000000400,00N541NONREF |
|||
NL66RABO0160878799 |
|||
:86:/ORDP//NAME/R. SMITH/ADDR/Green market 74 3311BE Sheepcity Nederl |
|||
and NL/REMI/Test money paid by other partner: |
|||
/ISDT/2014-01-02 |
|||
:62F:C140102EUR000000004833,52 |
|||
:20:940S140103 |
|||
:25:NL34RABO0142623393 EUR |
|||
:28C:0 |
|||
:60F:C140102EUR000000004833,52 |
|||
:62F:C140103EUR000000004833,52 |
|||
:20:940S140106 |
|||
:25:NL34RABO0142623393 EUR |
|||
:28C:0 |
|||
:60F:C140103EUR000000004833,52 |
|||
:61:140101D000000000034,61N093NONREF |
|||
:86:/BENM//NAME/Kosten/REMI/Periode 01-10-2013 t/m 31-12-2013/ISDT/20 |
|||
14-01-01 |
|||
:62F:C140106EUR000000004798,91 |
|||
:20:940S140107 |
|||
:25:NL34RABO0142623393 EUR |
|||
:28C:0 |
|||
:60F:C140106EUR000000004798,91 |
|||
:62F:C140107EUR000000004798,91 |
@ -0,0 +1,78 @@ |
|||
{1:F01SNSBNL2AXXXX0000000000}{2:O940SNSBNL2AXXXXN}{3:}{4: |
|||
:20:0000000000 |
|||
:25:NL05SNSB0908244436 |
|||
:28C:361/1 |
|||
:60F:C171227EUR3026,96 |
|||
:61:1712271227D713,13NOVBNL49RABO0166416932 |
|||
gerrits glas en schilderwerk |
|||
:86:NL49RABO0166416932 gerrits glas en schilderwerk |
|||
|
|||
Factuur 17227/248/20 |
|||
|
|||
|
|||
|
|||
:61:1712271227D10,18NBEA//228ohu/972795 |
|||
:86: |
|||
|
|||
Jumbo Wijchen B.V. >WIJCHEN 27.12.2017 13U38 KV005 4XZJ4Z M |
|||
CC:5411 Contactloze betaling |
|||
|
|||
|
|||
:61:1712271227D13,52NINCNL94INGB0000869000 |
|||
vitens nv |
|||
:86:NL94INGB0000869000 vitens nv |
|||
|
|||
Europese incasso door:VITENS NV NL-Factuurnr 072304597540 VNKlant |
|||
nr 00000000000 BTW 0,77PC 6605 DW 6223, DEC-Incassant ID: NL84ZZZ0 |
|||
50695810000-Kenmerk Machtiging: bla |
|||
|
|||
:61:1712271227D25,61NBEA//229hro/195867 |
|||
:86: |
|||
|
|||
Albert Heijn 1370 >WIJCHEN 27.12.2017 19U13 KV006 70X708 M |
|||
CC:5411 |
|||
|
|||
|
|||
:62F:C171227EUR2264,52 |
|||
-}{5:} |
|||
{1:F01SNSBNL2AXXXX0000000000}{2:O940SNSBNL2AXXXXN}{3:}{4: |
|||
:20:0000000000 |
|||
:25:NL05SNSB0908244436 |
|||
:28C:362/1 |
|||
:60F:C171228EUR2264,52 |
|||
:61:1712281228D10,95NINCNL40RABO0127859497 |
|||
antagonist b.v. |
|||
:86:NL40RABO0127859497 antagonist b.v. |
|||
|
|||
Europese incasso door:ANTAGONIST B.V. NL-DDWPN954156 AI529942Cweb |
|||
share.nl-Incassant ID: NL65ZZZ091364410000-Kenmerk Machtiging: bla |
|||
|
|||
:61:1712281228C0,00NDIV |
|||
:86: |
|||
|
|||
Mobiel betalen is vanaf nu niet meer mogelijk voor B |
|||
ERG M A VAN DEN met Lenovo P2 |
|||
|
|||
|
|||
:62F:C171228EUR2253,57 |
|||
-}{5:} |
|||
{1:F01SNSBNL2AXXXX0000000000}{2:O940SNSBNL2AXXXXN}{3:}{4: |
|||
:20:0000000000 |
|||
:25:NL05SNSB0908244436 |
|||
:28C:363/1 |
|||
:60F:C171229EUR2253,57 |
|||
:61:1712291229D907,29NINCNL19ABNA0427093546 |
|||
florius |
|||
:86:NL19ABNA0427093546 florius |
|||
|
|||
Europese incasso door:FLORIUS NL-Verschuldigde bedragen PERIODE 1 |
|||
2-2017-Incassant ID: NL42ZZZ080242850000-Kenmerk Machtiging: bla |
|||
|
|||
:61:1712291229D35,00NINCNL28DEUT0265186439 |
|||
stichting derdengelden bucka |
|||
:86:NL28DEUT0265186439 stichting derdengelden bucka |
|||
|
|||
Europese incasso door:STICHTING DERDENGELDEN BUCKAROO-T-Mobile Th |
|||
uis B.V.: Rekening dec 2017. Bekijk je rekening op thuismy.t-mobi |
|||
le.nl-Incassant ID: NL39ZZZ302317620000-Kenmerk Machtiging: bla |
|||
-}{5:} |
@ -0,0 +1,11 @@ |
|||
:9401: |
|||
:20:940S140102 |
|||
:25:NL34RABO0142623393 EUR |
|||
:28C:0 |
|||
:60F:C131231EUR000000004433,52 |
|||
:61:140102C000000000400,00N541NONREF |
|||
NL66RABO0160878799 |
|||
:86:/ORDP//NAME/R. SMITH/ADDR/Green market 74 3311BE Sheepcity Nederl |
|||
and NL/REMI/Test money paid by other partner: |
|||
/ISDT/2014-01-02 |
|||
:62F:C140102EUR000000004833,52 |
@ -0,0 +1 @@ |
|||
from . import test_import_bank_statement |
@ -0,0 +1,240 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# Copyright 2017 Onestein (<http://www.onestein.eu>) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
import base64 |
|||
from mock import patch |
|||
from odoo.tests.common import TransactionCase |
|||
from odoo.modules.module import get_module_resource |
|||
from ..mt940 import MT940, get_subfields, handle_common_subfields |
|||
|
|||
|
|||
class TestImport(TransactionCase): |
|||
"""Run test to import mt940 import.""" |
|||
transactions = [ |
|||
{ |
|||
'account_number': 'NL46ABNA0499998748', |
|||
'amount': -754.25, |
|||
'ref': '435005714488-ABNO33052620', |
|||
'name': 'test line', |
|||
}, |
|||
] |
|||
|
|||
def setUp(self): |
|||
super(TestImport, self).setUp() |
|||
bank1 = self.env['res.partner.bank'].create({ |
|||
'acc_number': 'NL77INGB0574908765', |
|||
'partner_id': self.env.ref('base.main_partner').id, |
|||
'company_id': self.env.ref('base.main_company').id, |
|||
'bank_id': self.env.ref('base.res_bank_1').id, |
|||
}) |
|||
self.env['account.journal'].create({ |
|||
'name': 'Bank Journal - (test1 mt940)', |
|||
'code': 'TBNK1MT940', |
|||
'type': 'bank', |
|||
'bank_account_id': bank1.id, |
|||
'currency_id': self.env.ref('base.EUR').id, |
|||
}) |
|||
bank2 = self.env['res.partner.bank'].create({ |
|||
'acc_number': 'NL34RABO0142623393', |
|||
'partner_id': self.env.ref('base.main_partner').id, |
|||
'company_id': self.env.ref('base.main_company').id, |
|||
'bank_id': self.env.ref('base.res_bank_1').id, |
|||
}) |
|||
self.env['account.journal'].create({ |
|||
'name': 'Bank Journal - (test2 mt940)', |
|||
'code': 'TBNK2MT940', |
|||
'type': 'bank', |
|||
'bank_account_id': bank2.id, |
|||
'currency_id': self.env.ref('base.EUR').id, |
|||
}) |
|||
bank3 = self.env['res.partner.bank'].create({ |
|||
'acc_number': 'NL05SNSB0908244436', |
|||
'partner_id': self.env.ref('base.main_partner').id, |
|||
'company_id': self.env.ref('base.main_company').id, |
|||
'bank_id': self.env.ref('base.res_bank_1').id, |
|||
}) |
|||
self.env['account.journal'].create({ |
|||
'name': 'Bank Journal - (test3 mt940)', |
|||
'code': 'TBNK3MT940', |
|||
'type': 'bank', |
|||
'bank_account_id': bank3.id, |
|||
'currency_id': self.env.ref('base.EUR').id, |
|||
}) |
|||
|
|||
self.data =\ |
|||
"/BENM//NAME/Cost/REMI/Period 01-10-2013 t/m 31-12-2013/ISDT/20" |
|||
self.codewords = ['BENM', 'ADDR', 'NAME', 'CNTP', 'ISDT', 'REMI'] |
|||
|
|||
def test_wrong_file_import(self): |
|||
"""Test wrong file import.""" |
|||
testfile = get_module_resource( |
|||
'account_bank_statement_import_mt940_base', |
|||
'test_files', |
|||
'test-wrong-file.940', |
|||
) |
|||
parser = MT940() |
|||
datafile = open(testfile, 'rb').read() |
|||
with self.assertRaises(ValueError): |
|||
parser.parse(datafile, header_lines=1) |
|||
|
|||
def test_statement_import(self): |
|||
"""Test correct creation of single statement ING.""" |
|||
|
|||
def _prepare_statement_lines(statements): |
|||
transact = self.transactions[0] |
|||
for st_vals in statements[2]: |
|||
for line_vals in st_vals['transactions']: |
|||
line_vals['amount'] = transact['amount'] |
|||
line_vals['name'] = transact['name'] |
|||
line_vals['account_number'] = transact['account_number'] |
|||
line_vals['ref'] = transact['ref'] |
|||
|
|||
testfile = get_module_resource( |
|||
'account_bank_statement_import_mt940_base', |
|||
'test_files', |
|||
'test-ing.940', |
|||
) |
|||
parser = MT940() |
|||
datafile = open(testfile, 'rb').read() |
|||
statements = parser.parse(datafile, header_lines=1) |
|||
|
|||
_prepare_statement_lines(statements) |
|||
|
|||
path_addon = 'odoo.addons.account_bank_statement_import.' |
|||
path_file = 'account_bank_statement_import.' |
|||
path_class = 'AccountBankStatementImport.' |
|||
method = path_addon + path_file + path_class + '_parse_file' |
|||
with patch(method) as my_mock: |
|||
my_mock.return_value = statements |
|||
|
|||
action = self.env['account.bank.statement.import'].create({ |
|||
'data_file': base64.b64encode(datafile), |
|||
}).import_file() |
|||
|
|||
transact = self.transactions[0] |
|||
for statement in self.env['account.bank.statement'].browse( |
|||
action['context']['statement_ids']): |
|||
for line in statement.line_ids: |
|||
self.assertTrue( |
|||
line.bank_account_id.acc_number == |
|||
transact['account_number']) |
|||
self.assertTrue(line.amount == transact['amount']) |
|||
self.assertTrue(line.date == '2014-02-20') |
|||
self.assertTrue(line.name == transact['name']) |
|||
self.assertTrue(line.ref == transact['ref']) |
|||
|
|||
def test_get_subfields(self): |
|||
"""Unit Test function get_subfields().""" |
|||
|
|||
res = get_subfields(self.data, self.codewords) |
|||
espected_res = { |
|||
'BENM': [''], |
|||
'NAME': ['Cost'], |
|||
'REMI': ['Period 01-10-2013 t', 'm 31-12-2013'], |
|||
'ISDT': ['20'], |
|||
} |
|||
self.assertTrue(res == espected_res) |
|||
|
|||
def test_handle_common_subfields(self): |
|||
"""Unit Test function handle_common_subfields().""" |
|||
|
|||
subfields = get_subfields(self.data, self.codewords) |
|||
transaction = self.transactions[0] |
|||
|
|||
handle_common_subfields(transaction, subfields) |
|||
|
|||
def test_statement_import2(self): |
|||
"""Test correct creation of single statement RABO.""" |
|||
|
|||
def _prepare_statement_lines(statements): |
|||
transact = self.transactions[0] |
|||
for st_vals in statements[2]: |
|||
for line_vals in st_vals['transactions']: |
|||
line_vals['amount'] = transact['amount'] |
|||
line_vals['name'] = transact['name'] |
|||
line_vals['account_number'] = transact['account_number'] |
|||
line_vals['ref'] = transact['ref'] |
|||
|
|||
testfile = get_module_resource( |
|||
'account_bank_statement_import_mt940_base', |
|||
'test_files', |
|||
'test-rabo.swi', |
|||
) |
|||
parser = MT940() |
|||
parser.header_regex = '^:940:' # Start of header |
|||
parser.header_lines = 1 # Number of lines to skip |
|||
datafile = open(testfile, 'rb').read() |
|||
statements = parser.parse(datafile, header_lines=1) |
|||
|
|||
_prepare_statement_lines(statements) |
|||
|
|||
path_addon = 'odoo.addons.account_bank_statement_import.' |
|||
path_file = 'account_bank_statement_import.' |
|||
path_class = 'AccountBankStatementImport.' |
|||
method = path_addon + path_file + path_class + '_parse_file' |
|||
with patch(method) as my_mock: |
|||
my_mock.return_value = statements |
|||
|
|||
action = self.env['account.bank.statement.import'].create({ |
|||
'data_file': base64.b64encode(datafile), |
|||
}).import_file() |
|||
# The file contains 4 statements, but only 2 with transactions |
|||
self.assertTrue(len(action['context']['statement_ids']) == 2) |
|||
transact = self.transactions[0] |
|||
for statement in self.env['account.bank.statement'].browse( |
|||
action['context']['statement_ids']): |
|||
for line in statement.line_ids: |
|||
self.assertTrue( |
|||
line.bank_account_id.acc_number == |
|||
transact['account_number']) |
|||
self.assertTrue(line.amount == transact['amount']) |
|||
self.assertTrue(line.date) |
|||
self.assertTrue(line.name == transact['name']) |
|||
self.assertTrue(line.ref == transact['ref']) |
|||
|
|||
def test_statement_import3(self): |
|||
"""Test correct creation of multiple statements SNS.""" |
|||
|
|||
def _prepare_statement_lines(statements): |
|||
transact = self.transactions[0] |
|||
for st_vals in statements[2]: |
|||
for line_vals in st_vals['transactions']: |
|||
line_vals['amount'] = transact['amount'] |
|||
line_vals['name'] = transact['name'] |
|||
line_vals['account_number'] = transact['account_number'] |
|||
line_vals['ref'] = transact['ref'] |
|||
|
|||
testfile = get_module_resource( |
|||
'account_bank_statement_import_mt940_base', |
|||
'test_files', |
|||
'test-sns.940', |
|||
) |
|||
parser = MT940() |
|||
datafile = open(testfile, 'rb').read() |
|||
statements = parser.parse(datafile, header_lines=1) |
|||
|
|||
_prepare_statement_lines(statements) |
|||
|
|||
path_addon = 'odoo.addons.account_bank_statement_import.' |
|||
path_file = 'account_bank_statement_import.' |
|||
path_class = 'AccountBankStatementImport.' |
|||
method = path_addon + path_file + path_class + '_parse_file' |
|||
with patch(method) as my_mock: |
|||
my_mock.return_value = statements |
|||
|
|||
action = self.env['account.bank.statement.import'].create({ |
|||
'data_file': base64.b64encode(datafile), |
|||
}).import_file() |
|||
self.assertTrue(len(action['context']['statement_ids']) == 3) |
|||
transact = self.transactions[-1] |
|||
for statement in self.env['account.bank.statement'].browse( |
|||
action['context']['statement_ids'][-1]): |
|||
for line in statement.line_ids: |
|||
self.assertTrue( |
|||
line.bank_account_id.acc_number == |
|||
transact['account_number']) |
|||
self.assertTrue(line.amount == transact['amount']) |
|||
self.assertTrue(line.date == statement.date) |
|||
self.assertTrue(line.name == transact['name']) |
|||
self.assertTrue(line.ref == transact['ref']) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue