railslove / cmxl

your friendly MT940 SWIFT file parser for bank statements
http://railslove.com
MIT License
46 stars 25 forks source link

Statement Field generation_date NoMethodError: undefined method `date' for nil:NilClass #35

Open TobiTobiM opened 4 years ago

TobiTobiM commented 4 years ago

First of all thanks for sharing the code.

I updated cmxl version in my project from 0.2.0 to 1.4.1. Then one of my tests parsing a mt940 is failing. Quickly i found why this happens. Generation_date in statement wants to read from field :20 or :13 In my case i get from my bank (Commerzbank) field :20 only with reference no extra values are provided. Field :13 is not provided at all because it is mt942.

def generation_date field(20).date || field(13).date end

Call of field(13) gives nil and then method date fails with

NoMethodError: undefined method `date' for nil:NilClass

:20 exists in mt940 and mt942 so even if there is no generation_date provided in that field field(20).date will not fail. It only returns nil. But then field(13).date is called and gives error mentioned above.

Method generation_date should check if field :13 is provided before call date on it.

bumi commented 4 years ago

Thanks for reporting this. and without checking the code and the specs this check sounds like a good addition. Do you want to make a PR for that? that would be amazing!

TobiTobiM commented 4 years ago

Sure i can provide a PR. I checked the rspecs as far i can see generation_date is not called. That seems to be the reason why no rpsec is failing.

Edit: I have to revise my statement above. Generation_date is called but all examples have numbers in :20. In my case :20 has a alphanumeric reference

bumi commented 4 years ago

Thanks a lot for the pull request! PR: #36