Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] account_statement_import_camt: multi account support #666

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions account_statement_import_camt/models/account_statement_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@
except ValueError:
try:
with zipfile.ZipFile(BytesIO(data_file)) as data:
currency = None
account_number = None
transactions = []
result = []
for member in data.namelist():
currency, account_number, new = self._parse_file(
data.open(member).read()
)
transactions.extend(new)
return currency, account_number, transactions
res = self._parse_file(data.open(member).read())
if isinstance(res, tuple):
res = [res]

Check warning on line 28 in account_statement_import_camt/models/account_statement_import.py

View check run for this annotation

Codecov / codecov/patch

account_statement_import_camt/models/account_statement_import.py#L28

Added line #L28 was not covered by tests
result += res
return result
# pylint: disable=except-pass
except (zipfile.BadZipFile, ValueError):
pass
Expand Down
10 changes: 7 additions & 3 deletions account_statement_import_camt/models/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Copyright 2017 Open Net Sàrl
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import re
from collections import defaultdict

from lxml import etree

Expand Down Expand Up @@ -444,7 +445,7 @@ def parse(self, data):
raise ValueError("Not a valid xml file, or not an xml file at all.")
ns = root.tag[1 : root.tag.index("}")]
self.check_version(ns, root)
statements = []
statements = defaultdict(list)
currency = None
account_number = None
for node in root[0][1:]:
Expand All @@ -454,5 +455,8 @@ def parse(self, data):
currency = statement.pop("currency")
if "account_number" in statement:
account_number = statement.pop("account_number")
statements.append(statement)
return currency, account_number, statements
statements[(currency, account_number)].append(statement)
return [
(currency, account_number, statement_list)
for (currency, account_number), statement_list in statements.items()
]
Original file line number Diff line number Diff line change
@@ -1 +1 @@
(None, None, [])
[]
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
('CHF',
'CH1111000000123456789',
[{'balance_end_real': 79443.15,
'balance_start': 75960.15,
'date': '2017-03-22',
'name': '20170323123456789012345',
'transactions': [{'account_number': 'CH2222000000123456789',
'amount': 2187.0,
'date': '2017-03-22',
'narration': 'Partner Name (RltdPties/Nm): Banque Cantonale Vaudoise\n'
'Partner Account Number (RltdPties/Acct): CH2222000000123456789\n'
'Transaction Date (BookgDt): 2017-03-22\n'
'Reference: 302388292000011111111111111\n'
'Communication: \n'
'Transaction Type (BkTxCd): PMNT-RCDT-VCOM\n'
'Additional Entry Information (AddtlNtryInf): CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: '
'123456CHCAFEBABE\n'
'Reversal Indicator (RvslInd): false\n'
'Structured Reference (RmtInf/Strd/CdtrRefInf/Ref): 302388292000011111111111111\n'
'Account Servicer Reference (Refs/AcctSvcrRef): 123456CHCAFEBABE\n'
'Postal Address (PstlAdr): Place Saint-François | 14 | 1003 | Lausanne | CH1',
'partner_name': 'Banque Cantonale Vaudoise',
'payment_ref': '/',
'ref': '302388292000011111111111111',
'transaction_type': 'PMNT-RCDT-VCOM'},
{'account_number': 'CH3333000000123456789',
'amount': 1296.0,
'date': '2017-03-22',
'narration': 'Partner Name (RltdPties/Nm): Banque Cantonale Vaudoise\n'
'Partner Account Number (RltdPties/Acct): CH3333000000123456789\n'
'Transaction Date (BookgDt): 2017-03-22\n'
'Reference: 302388292000022222222222222\n'
'Communication: \n'
'Transaction Type (BkTxCd): PMNT-RCDT-VCOM\n'
'Additional Entry Information (AddtlNtryInf): CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET ID: '
'123456CHCAFEBABE\n'
'Reversal Indicator (RvslInd): false\n'
'Structured Reference (RmtInf/Strd/CdtrRefInf/Ref): 302388292000022222222222222\n'
'Account Servicer Reference (Refs/AcctSvcrRef): 123456CHCAFEBABE\n'
'Postal Address (PstlAdr): Place Saint-François | 14 | 1003 | Lausanne | CH2',
'partner_name': 'Banque Cantonale Vaudoise',
'payment_ref': '/',
'ref': '302388292000022222222222222',
'transaction_type': 'PMNT-RCDT-VCOM'}]}])
[('CHF',
'CH1111000000123456789',
[{'balance_end_real': 79443.15,
'balance_start': 75960.15,
'date': '2017-03-22',
'name': '20170323123456789012345',
'transactions': [{'account_number': 'CH2222000000123456789',
'amount': 2187.0,
'date': '2017-03-22',
'narration': 'Partner Name (RltdPties/Nm): Banque Cantonale Vaudoise\n'
'Partner Account Number (RltdPties/Acct): CH2222000000123456789\n'
'Transaction Date (BookgDt): 2017-03-22\n'
'Reference: 302388292000011111111111111\n'
'Communication: \n'
'Transaction Type (BkTxCd): PMNT-RCDT-VCOM\n'
'Additional Entry Information (AddtlNtryInf): CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET '
'ID: 123456CHCAFEBABE\n'
'Reversal Indicator (RvslInd): false\n'
'Structured Reference (RmtInf/Strd/CdtrRefInf/Ref): 302388292000011111111111111\n'
'Account Servicer Reference (Refs/AcctSvcrRef): 123456CHCAFEBABE\n'
'Postal Address (PstlAdr): Place Saint-François | 14 | 1003 | Lausanne | CH1',
'partner_name': 'Banque Cantonale Vaudoise',
'payment_ref': '/',
'ref': '302388292000011111111111111',
'transaction_type': 'PMNT-RCDT-VCOM'},
{'account_number': 'CH3333000000123456789',
'amount': 1296.0,
'date': '2017-03-22',
'narration': 'Partner Name (RltdPties/Nm): Banque Cantonale Vaudoise\n'
'Partner Account Number (RltdPties/Acct): CH3333000000123456789\n'
'Transaction Date (BookgDt): 2017-03-22\n'
'Reference: 302388292000022222222222222\n'
'Communication: \n'
'Transaction Type (BkTxCd): PMNT-RCDT-VCOM\n'
'Additional Entry Information (AddtlNtryInf): CRÉDIT GROUPÉ BVR TRAITEMENT DU 22.03.2017 NUMÉRO CLIENT 01-70884-3 PAQUET '
'ID: 123456CHCAFEBABE\n'
'Reversal Indicator (RvslInd): false\n'
'Structured Reference (RmtInf/Strd/CdtrRefInf/Ref): 302388292000022222222222222\n'
'Account Servicer Reference (Refs/AcctSvcrRef): 123456CHCAFEBABE\n'
'Postal Address (PstlAdr): Place Saint-François | 14 | 1003 | Lausanne | CH2',
'partner_name': 'Banque Cantonale Vaudoise',
'payment_ref': '/',
'ref': '302388292000022222222222222',
'transaction_type': 'PMNT-RCDT-VCOM'}]}])]
Loading
Loading