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

reading transaction closing balance (record :62F:) #18

Closed
benkonrath opened this issue Feb 4, 2016 · 12 comments
Closed

reading transaction closing balance (record :62F:) #18

benkonrath opened this issue Feb 4, 2016 · 12 comments

Comments

@benkonrath
Copy link
Contributor

Is it possible to access the transaction closing balance (record :62F:)? I don't see this in transaction.data? I've read through the docs but I'm still not sure how to get this piece of information. I did find mt940.models.Balance for parsing this information but I'm not sure how to use this to get the information in record :62F:. Thanks for your help.

@benkonrath
Copy link
Contributor Author

I'd also like to read record :60F: from a transaction. Thanks.

@wolph
Copy link
Owner

wolph commented Feb 4, 2016

@benkonrath
Copy link
Contributor Author

I think the format of the records in the MT940 file I'm using are OK. I can see the final_opening_balance and final_closing_balance for the last record / transaction in the parsed MT940 file but I want to get this information for each record / transaction.

For instance, if I parse the MT940 file like this:

transactions = mt940.parse('path/to/abnamro.sta')
transaction = transactions[0]

What Python code would get me the values of the :60F: and :62F: fields for this specific transaction?

@wolph
Copy link
Owner

wolph commented Feb 4, 2016

Well, it's scoped to Transactions by default but that's easily fixable with a little monkeypatch. I believe this should do the trick:

from mt940 import tags
from mt940 import models

tags.BalanceBase.scope = models.Transaction

transactions = mt940.parse('path/to/abnamro.sta')
transaction = transactions[0]

@benkonrath
Copy link
Contributor Author

Thanks, I'll try it out tomorrow. Is there documentation that I missed about this?

@wolph
Copy link
Owner

wolph commented Feb 4, 2016 via email

@benkonrath
Copy link
Contributor Author

That didn't work. Here's what I get:

>>> import mt940
>>> from mt940 import tags
>>> from mt940 import models
>>> tags.BalanceBase.scope = models.Transaction
>>> transactions = mt940.parse('/home/ben/abnamro.sta')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ben/Development/project/env/lib/python2.7/site-packages/mt940/parser.py", line 45, in parse
    transactions.parse(data)
  File "/home/ben/Development/project/env/lib/python2.7/site-packages/mt940/models.py", line 232, in parse
    transaction.data[k] += '\n%s' % v.strip()
AttributeError: 'Balance' object has no attribute 'strip'

Any ideas? Thanks again for your help on this.

@wolph
Copy link
Owner

wolph commented Feb 10, 2016

I've just pushed a new release to the dev which fixes this issue. The proper fix is going to take a bit more time but perhaps this already does the trick for you :)

@benkonrath
Copy link
Contributor Author

Thanks, this should be fine for my needs.

From a high level, it makes sense to me that the balance information is available by default on each Transaction but it's also reasonable to just add documentation on how to do this with a monkey patch. Let me know if you prefer to monkey patch solution and I'll make a PR to add this to the docs.

I'm working on some other stuff now but I'll get back to using this soon. Thanks again for your help.

@wolph
Copy link
Owner

wolph commented Feb 11, 2016

Ultimately it would be nice to do both, but since that will take a bit more work I think docs would be preferable for the time being.

Thanks for the help!

@benkonrath
Copy link
Contributor Author

I'm just getting back to this now. It seems like record :60F: comes before record :61:. With the monkey patch applied, the opening and closing balance info isn't correct for the transaction because the transaction is created only when a :61: is found. This means the opening and closing balances can be set to the wrong transaction.

I've made a PR just for discussion but it's not correct yet. I'll make an update in a few minutes with an explanation.

@benkonrath
Copy link
Contributor Author

benkonrath commented Apr 26, 2016

Fixed via a898b96.

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

2 participants