Skip to content

Transaction Reference Number is not returned by the parser #102

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

Closed
denisld opened this issue Mar 7, 2023 · 5 comments
Closed

Transaction Reference Number is not returned by the parser #102

denisld opened this issue Mar 7, 2023 · 5 comments

Comments

@denisld
Copy link

denisld commented Mar 7, 2023

The Transaction object does not contain the mandatory SWIFT Transaction Reference Number (Tag :20:). It only includes the field called 'bank_reference', which appears to be extracted from the section with Tag :61:. These two numbers are not the same, and I would imagine many users require at least the Tag 20 entry.

@wolph
Copy link
Owner

wolph commented Mar 27, 2023

There should be a transaction_reference available for a :20::

pattern = r'(?P<transaction_reference>.{0,16})'

We can see an example with this sta file here:

Which generates this data:

transaction_reference: STARTUMSE

Do you have a specific example where this is not working?

@mmdevl
Copy link

mmdevl commented Apr 4, 2023

You can find the transaction reference as follow:

transactions = mt940.parse('test.sta')
print(transactions.data['transaction_reference'])

But for instance my bank exports several transaction references at the same time (one for each account). And with the print above you would get only the last transaction reference.

Try with this example:

:20:STARTUMSE
:25:12345678/1020304050
:28C:00000/001
:60F:C160229EUR1200,00
:61:1602300301DR6,00N024NONREF
:86:805?00ENTGELTABSCHLUSS?106666?20Pauschalen?3012345678?1122334
45566?602017-01-01T13
:12:11
:62F:C160301EUR1194,00
:20:STARTUMSE2
:25:12345678/1020304050
:28C:00000/001
:60F:C160229EUR1200,00
:61:1602300301DR6,00N024NONREF
:86:805?00ENTGELTABSCHLUSS?106666?20Pauschalen?3012345678?1122334
45566?602017-01-01T13
:12:11
:62F:C160301EUR1194,00

I think this is a bug and I see 2 solutions:

  1. add a 'transaction_reference' key to every transaction objects or
  2. group the objects by 'transaction_reference'

@wolph wolph closed this as completed in 76a0bd0 Apr 13, 2023
@wolph
Copy link
Owner

wolph commented Apr 13, 2023

You're right. For some files this is indeed not a usable situation. Option 2 is quite involved so I've opted for adding a transformer to take care of option 1. I'm still finalizing the code so the tests keep on working without issues but the current develop branch shows the new behaviour.

wolph added a commit that referenced this issue Apr 13, 2023
Added processor to fix #102 v4.30.0

# -----BEGIN PGP SIGNATURE-----
#
# iQIzBAABCgAdFiEEFJMl/RWQTpxOuJ6V6BRE6c4faV0FAmQ34hYACgkQ6BRE6c4f
# aV3a7w//UMH7KR0iXpkRL4+G/D6ZVg1U+iicbyhCYQmH+oo+JLCzBspq488G6jWg
# AwB6HUadJ3gYSO2KL11jjhLqhQYorzYQ/jYrYBR65xzwTVObR8vm+YLAPgLI9zT1
# yFlOiTj9aYYcvPc8HVCxXvUfQJR19bhCqiNx9QvDgNlkYNxCwZm9jw6aeDiVROIx
# 9PmmZSfNQhhNdxbx18qjfcOtyaQ+2BCjsNfdHOLDh3seZhDeBb781XWB+GHX379Q
# ARJSi2em4edqy9EME5RFT3nKfK2yvSz+xV7e0+DCs7FP2fis99H1I8Ps6zATED+K
# frA1xAaBIZO6mP7YhYawe7hjlEWVLm5eyRzsAbu08QRyJ5emF7Jg0NsqOgA6yzbE
# 7X0X48+KUEY9g1q8z+YCM6OMMJz7akGACsB28queKPRNpvC+S9L03v6TmrGkf7up
# Unxul9zmPvdGJaEYgSv+lh65RGDfY3jrVdyxlHwSLR6tqeogS3TguRPgVgp+lPbq
# qIEPE2GZJKoAPtqd0KE4RzItbvp6t+/2RCS5HOesWtgluXzrIp67VJ+XrPxCSsJ+
# 1uuOwTeBU1u70t5GNC8m6F2clRE8EL4avb+snnbQADNv48EhrjU4OPFiI7kwz8pG
# Vdz9LXutX6h7RLIgYxeJQSmHU9LwSqU2+JY4PO/SvZeZb79/dmk=
# =IW9G
# -----END PGP SIGNATURE-----
# gpg: Signature made Thu Apr 13 13:05:58 2023 CEST
# gpg:                using RSA key 149325FD15904E9C4EB89E95E81444E9CE1F695D
# gpg: Good signature from "Rick van Hattem <[email protected]>" [ultimate]
# gpg:                 aka "[jpeg image of size 9662]" [ultimate]
@wolph
Copy link
Owner

wolph commented Apr 13, 2023

The new release is online. Every transaction should have the relevant transaction_reference now. If you want to add more fields you can do so using the post processors:

mt940/mt940/models.py

Lines 264 to 267 in 026859d

post_statement=[
processors.date_cleanup_post_processor,
processors.transactions_to_transaction('transaction_reference'),
],

@aGitForEveryone
Copy link

Amazing fix! This same issue happens when a single mt940 file contains transactions for several bank accounts. The account_identification field in transactions.data would have the value of the last tag 25. So it was impossible to track after transaction parsing what bank account the transaction belonged to.

I implemented a more complex workaround to separate the transactions per bank account. But with this post processor, it's possible to include that information in the transaction data itself. So the parsing becomes much easier.

Now don't forget that the global transactions.data gets overwritten with each new transaction, otherwise this feature doesn't work anymore.

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

4 participants