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

Parsing transactions : key 64 #85

Closed
elisaprio opened this issue Jun 8, 2020 · 8 comments
Closed

Parsing transactions : key 64 #85

elisaprio opened this issue Jun 8, 2020 · 8 comments

Comments

@elisaprio
Copy link

Hello
First thank you so much for this parser !

In result.get("additional_purpose","").replace("\r\n"," ") key ?64 is missing. It's a part of the address. Could it be added in "additional_purpose" field ?

And for those address related keys, could spaces be added between each key (for example write something like result[key60] = f"{result[key60] or ''} {value}" instead of result[key60] = (result[key60] or '') + value ) in order to facilitate future address parsing ?

Thank you in advance for your work,

Elisa

@wolph
Copy link
Owner

wolph commented Jun 9, 2020

The additional_purpose gets parsed by the transaction_details_post_processor:
https://github.com/WoLpH/mt940/blob/ecb8c9fb31267a90780a279c40c2af1ea8c95d1e/mt940/processors.py#L198-L214

If you would add an extra post processor in post_transaction_details you could get it parsed. It's probably something specific for your bank:

import mt940
import pprint

mt940.tags.BalanceBase.scope = mt940.models.Transaction

# The currency has to be set manually when setting the BalanceBase scope to Transaction.
transactions = mt940.models.Transactions(processors=dict(
    post_transaction_details=[
        <your processors>
    ],
))

with open('filename.sta') as f:
    data = f.read()

transactions.parse(data)

for transaction in transactions:
    print('Transaction: ', transaction)
    pprint.pprint(transaction.data)

@elisaprio
Copy link
Author

Hi
Thanks for your quick answer.

Sorry I realised I pasted the wrong thing in my message yesterday. I meant in the method _parse_mt940_details there is a test elif key in ('61', '62', '63') but when I read some documentation related to mt940 extended format, I see that for tag 86 "information to account owner" it goes from 60 to 65. I read that in multine doc but it's only available in french. Other banks documentation also talk about thoses keys.
So I believe subkeys ?64 and ?65 are not parsed. So data is missing for the key additional_purpose in my parsed Transactions() object.
To do the parsing, I use the parse method from Transactions model.

Do you think it's possible to fix that, since I don't think it's specific to my bank but to mt940 extended format ? I think it's somehow the same problem as for this PR : #48

@wolph wolph closed this as completed in 6215667 Jun 16, 2020
wolph added a commit that referenced this issue Jun 16, 2020
added support for more "additional purpose" keys to fix #85 v4.22.0

# gpg: Signature made Wed Jun 17 01:28:43 2020 CEST
# gpg:                using RSA key 149325FD15904E9C4EB89E95E81444E9CE1F695D
# gpg: checking the trustdb
# gpg: marginals needed: 3  completes needed: 1  trust model: pgp
# gpg: depth: 0  valid:   3  signed:   1  trust: 0-, 0q, 0n, 0m, 0f, 3u
# gpg: depth: 1  valid:   1  signed:   0  trust: 1-, 0q, 0n, 0m, 0f, 0u
# gpg: next trustdb check due at 2021-07-23
# gpg: Good signature from "Rick van Hattem <wolph@wol.ph>" [ultimate]
# gpg:                 aka "[jpeg image of size 9662]" [ultimate]
@wolph
Copy link
Owner

wolph commented Jun 17, 2020

I've created a new release that has this fix. Can you check if it works for you @elisaprio?

Sorry for the slow response, I've been really busy so it's hard to find time

@elisaprio
Copy link
Author

Thank you so much ! This will work for me. Do you think it would be also be possible to add a blank space before adding the new value ? Or is it unwise ?
Something like : result[key60] = f"{result[key60] or ''} {value}" instead of result[key60] = (result[key60] or '') + value

And sorry for the late reply too ! So no problem for the time =)

@wolph
Copy link
Owner

wolph commented Jun 25, 2020

The problem is (and with the entire standard in general) that nearly every bank has its own interpretation of the standard. While it might fix it for your bank, it will breakt it for some others.

I can add it as a configurable option though, from what I see in my tests there's not single testfile that currently has a format where it makes a difference though. Do you have an example file by any chance?

wolph added a commit that referenced this issue Jun 25, 2020
added optional support for spaces in extra details post processor to fix #85 v4.23.0

# gpg: Signature made Thu Jun 25 23:04:59 2020 CEST
# gpg:                using RSA key 149325FD15904E9C4EB89E95E81444E9CE1F695D
# gpg: Good signature from "Rick van Hattem <wolph@wol.ph>" [ultimate]
# gpg:                 aka "[jpeg image of size 9662]" [ultimate]
@wolph
Copy link
Owner

wolph commented Jun 25, 2020

Looks like there was actually 1 file that used this (and doesn't need the space).

You can use the version with spaces like this: https://github.com/WoLpH/mt940/blob/2e3669f9f0fd77abd5f4d5e58fe26b27f7620b40/mt940_tests/test_processors.py#L93-L97

@elisaprio
Copy link
Author

Thank you so much ! It works perfectly for me !!
Here is the file I use for my tests :
CCPM940EB20191025_215418_158_MULTILIE191025.dat_12_70855463.zip

@BeastOfBodmin
Copy link

Looks like there was actually 1 file that used this (and doesn't need the space).

You can use the version with spaces like this:

https://github.com/WoLpH/mt940/blob/2e3669f9f0fd77abd5f4d5e58fe26b27f7620b40/mt940_tests/test_processors.py#L93-L97

I realise this is a "How to use python" question, but how do I get at the results of the post_transaction_details?

import mt940
import pprint

# https://github.com/WoLpH/mt940/issues/85
transactions = mt940.parse('1591139129348.STA', processors=dict(
   post_transaction_details=[
        mt940.processors.transaction_details_post_processor,
   ],
))

for transaction in transactions:
    pprint.pprint(transactions.post_transaction_details)

results in

Traceback (most recent call last):
  File "mt940-test.transaction_details.py", line 16, in <module>
    pprint.pprint(transactions.post_transaction_details)
AttributeError: 'Transactions' object has no attribute 'post_transaction_details'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants