Friday, August 4, 2023

Most of the Belgian IBAN numbers in lino_xl.lib.sepa.fixtures.sample_ibans were actually invalid. Their IBAN check digit was correct, but the the programmers at www.mobilefish.com did not know that Belgian bank account numbers have their own check digit. I wrote the following doctest snippet to show only IBANs that are really valid. Statistically only one of 97 is valid. And indeed, I had to get 1000 fictive IBANS from mobilefish in order to harvest 10 good ones.

Edit 2023-08-06 Seems that Montenegro, Norway and Spain are like Belgium: they have check digits in national bank account numbers. And django-localflavor now also knows about them. So I need to update our sample_ibans.py file even mode.

>>> from lino import startup
>>> startup('lino_book.projects.voga2.settings')
>>> from lino.api.doctest import *
>>> from django.core.exceptions import ValidationError
>>> partner = rt.models.contacts.Partner.objects.first()
>>> Account = rt.models.sepa.Account
>>> ibans = """
... BE28724246719796 BE58483388989105 BE71734773678845 BE20174483803342
... BE71350811436250 BE18795488614610 BE84858551943938 BE32541820604815
... BE79203018402084 BE92227724179921 BE95657847530720 BE43887359333506
... BE05869216347393 BE13716672918550 BE09501756025056 BE25343348640131
... BE24862868507486 BE12202401892242 BE05430828656001 BE13677784802295
... BE05194204714338 BE85616511999691 BE93229218900239 BE32527262674483
... BE58067461123040 BE47884396692310 BE07364188327453 BE25882933953755
... BE36743323765718 BE67225381485065 BE79188638158195 BE02873579557797
... BE75032418043799 BE80296965174776 BE93322502171512 BE03181994160471
... BE41414473568385 BE87770998218656 BE74850873948015 BE82345649175398
... BE36315143736533 BE52849176505835 BE51427288306202 BE30999252618777
... BE95100449016428 BE46137417838797 BE16140712719138 BE70559894379973
... BE22338307655430 BE21744478962171 BE71698886383884 BE14776649354707
... BE49293501559571 BE12917065059682 BE03224307739576 BE89614705334946
... BE33025520765368 BE48644301836586 BE25869200566588 BE59398443056673
... BE05700351013001 BE93089106618187 BE53872384563730 BE23239846666050
... BE63289999168582 BE37977237425707 BE88226804784990 BE62994004047044
... BE96595371107901 BE27828364925134 BE41039439267385 BE60693753310146
... BE65327184565134 BE56614221337647 BE64494692585043 BE57105155123917
... BE26284315602949 BE29591695872615 BE37959588257665 BE68987243668796
... BE45339848048869 BE55790559805518 BE38848654741923 BE86388411676445
... BE18815106158450 BE83243857077493 BE26079576344270 BE34909685347786
... BE75136602618071 BE09595989391153 BE50000780506886 BE18764513455327
... BE25895552585494 BE06894601004584 BE98588934438901 BE22603142434371
... BE69478045723246 BE68355523201119 BE72921883510322 BE56680163678700
... BE54800210387334 BE14602195879124 BE14111760055869 BE85541535832328
... BE95454268362165 BE66224956682022 BE82747111508384 BE63097372245098
... BE39017955198559 BE54141796986685 BE02386289845249 BE33165363312439
... BE37048748480744 BE45544165675126 BE38554957819398 BE79623276881455
... BE89898236136387 BE42243901851491 BE98072909887412 BE50952449538745
... BE88119601752690 BE53064270609121 BE72120202551966 BE54073150762678
... BE58021988213001 BE29111649250074 BE50400776918739 BE41431198043381
... BE13404128585528 BE02397318558330 BE09840005458667 BE26552714094087
... BE66871155598522 BE55230546253482 BE21081301568124 BE31819267452784
... BE10602557401591 BE46110929739076 BE20492131301514 BE06175706664358
... BE87036264021027 BE40388531141018 BE10956348136305 BE14060594535639
... BE86406360676337 BE45186969681595 BE23081394358385 BE44153833882541
... BE82056316229523 BE51971075990111 BE09123506186860 BE77163131178008
... BE44094354583297 BE58515243244935 BE66527070962392 BE51455728344586
... BE14422646024996 BE95285529423235 BE79997405640022 BE79515119267402
... BE17294520366861 BE77659434470056 BE46437678380103 BE21046594839793
... BE28707245492257 BE66772298074615 BE65591592700051 BE08417691719646
... BE46994754655545 BE46994715585303 BE70198230882080 BE89786706663818
... BE83147213038781 BE20919908416561 BE52084284322416 BE77062925956471
... BE69926866200847 BE39971912183483 BE46152658693264 BE81995169644874
... BE60541297944643 BE81613962507635 BE75396642852203 BE39331066339247
... BE68091978629654 BE10201865242785 BE29955478077488 BE17642254548354
... BE78928625319741 BE76481174443473 BE88340025424235 BE39782462763107
... BE42030326767364 BE40507723623384 BE95378722370630 BE32565632366187
... BE36584235476583 BE46097919593318 BE91461112302870 BE28205672095343
... BE44195998043428 BE21861150713782 BE34066558619079 BE97495686032841
... BE24085603932842 BE12765411817734 BE71455656640371 BE06549670794137
... BE75287509344139 BE14676252110030 BE04451717299984 BE03246394845507
... BE52172466880408 BE28716937619446 BE67463379563939 BE26163669550654
... BE74247004641616 BE93792919154943 BE44476843358644 BE32260741612622
... BE15221821872539 BE20963639239289 BE55251585703250 BE16605977455807
... BE24087255453678 BE03547117460087 BE09256629686327 BE54447710192224
... BE50492124412325 BE75667145882210 BE87564352495593 BE15419133819199
... BE13832959147250 BE90566844867665 BE65829378217102 BE66603677788801
... BE54701121538409 BE64342015916077 BE23494486625099 BE59284163752638
... BE26972406338383 BE10475640265055 BE25014023940616 BE88208060378114
... BE40489011420411 BE03101360800721 BE60875447503698 BE74686132563967
... BE24247974947484 BE45664007197781 BE41890855214900 BE22692494338615
... BE65276303082923 BE39366664679647 BE14787967528107 BE38852937497563
... BE72731712721122 BE70295115332576 BE13736906734624 BE14707219749097
... BE38564130991640 BE32670485850228 BE87280359733495 BE09783848971732
... BE31687252082772 BE68438161760971 BE70173662148713 BE03082374528031
... BE83893940225618 BE06136453008356 BE19585174098553 BE80974324128873
... BE38868357557105 BE61037173495435 BE37691929441482 BE64299048243953
... BE32337470091678 BE43413671573901 BE58146083846226 BE50340320986150
... BE71333767856183 BE75309211783572 BE08409636850510 BE13695968136436
... BE35656234032345 BE94450163311804 BE34650063295980 BE42745684004821
... BE56453349648222 BE70288702006565 BE14131045229112 BE51529158472405
... BE53810212784367 BE91780121995904 BE97703964669812 BE69549508879827
... BE53501790349945 BE42536309052607 BE30020533437478 BE05514289019738
... BE32235606513230 BE91338863643153 BE57638748841340 BE03932968735390
... BE71038767281885 BE49745523130389 BE49284415413983 BE90358697467620
... BE27618825406018 BE11497546600798 BE89240330084926 BE02740696876932
... BE03164454824947 BE40316262308548 BE98597531902854 BE55540934033907
... BE02915819629526 BE86106703272689 BE85475487383557 BE23136532831387
... BE11804397580221 BE34829322365739 BE11458761645789 BE29130173930513
... BE29574484390883 BE19820541587867 BE73845165949471 BE11825210576117
... BE25499641614403 BE80564793249460 BE43437215784441 BE54138698693486
... BE61436161739340 BE27801411207953 BE55305014805004 BE13191398912855
... BE61189107260898 BE93312467480966 BE60440817758176 BE10863073287154
... BE59216818569552 BE07450905772904 BE85395276000288 BE57235129398589
... BE21523605221490 BE39687726524954 BE02785384795847 BE94282431297379
... BE37708963319221 BE20576597943736 BE58957930189048 BE89739470612521
... BE63988170278167 BE83796298703120 BE82296300383494 BE28129593595051
... BE24484557233273 BE69427657108123 BE57042159287068 BE83179882282306
... BE93341283519480 BE90729206219167 BE81269555020876 BE40766343569548
... BE53678632834066 BE93585347895031 BE69292012914179 BE49897120789494
... BE51985746520177 BE03895667683762 BE02408418329440 BE03609766419892
... BE78080963195984 BE68666652227996 BE54040081116636 BE35181410464917
... BE42606619499794 BE16513989595769 BE88647320882684 BE11272937316106
... BE38724890005186 BE07626747483096 BE02474894818162 BE53196039300567
... BE63988451926882 BE75182156579758 BE48386991558038 BE33952339454042
... BE56185415568252 BE34313568988032 BE03904423255096 BE77579995841458
... BE09071520707006 BE83207930496659 BE49318050525114 BE31056852421027
... BE51182515387458 BE42236944879280 BE50276834170512 BE58541970254007
... BE93271169674318 BE23136649204033 BE02851794180163 BE80778447523029
... BE21275778332339 BE51053181131687 BE56387983248355 BE38309089046355
... BE29002716425310 BE76365878771595 BE80911864086850 BE91136216227692
... BE08672781704375 BE34729906921209 BE85756866442049 BE48366731576602
... BE49519182254756 BE68035028622967 BE78277046396890 BE93837490942257
... BE66433528981837 BE86666893930914 BE15312933330011 BE43946329477713
... BE08594672453793 BE21433591412817 BE70467754184830 BE04374291204979
... BE64538515733632 BE87947327527963 BE51913563902956 BE04850007988759
... BE68155990881682 BE47473384527061 BE15906972704910 BE15944156398857
... BE14728111576893 BE71145331534847 BE92574219826420 BE92566945319180
... BE31013335466615 BE44090129621033 BE26226728108576 BE10231014323427
... BE68940179202254 BE56847196211284 BE55357359022868 BE23405282438663
... BE67824364770999 BE30009950029281 BE91377237232123 BE66386114502726
... BE60333519814092 BE44176520441100 BE67441017594540 BE27848533546247
... BE08833950119516 BE93975044034606 BE23645988190863 BE47472613381523
... BE54252608974116 BE87374084517534 BE42565800454106 BE98187154105383
... BE33050012842933 BE75116844443922 BE04699886831159 BE60044624208237
... BE20643226085265 BE32639360377999 BE93362702274071 BE19836703824285
... BE52073997617334 BE29024174274005 BE81349294644257 BE28732607237193
... BE55672277141733 BE36285935021940 BE54708460513595 BE34184510926957
... BE88170644701295 BE61709688753174 BE78965942728382 BE03956159662133
... BE35034870042820 BE67215399792312 BE90719088285064 BE51256194236566
... BE13167534988472 BE39947591745478 BE70077503814027 BE86161552353369
... BE86034767894306 BE74516318801696 BE94921930044512 BE28894110309803
... BE71054229463968 BE96536461902198 BE33518631756667 BE55668105864313
... """.split()
>>> def print_if_good(iban):
...    acct = Account(partner=partner, iban=iban, primary=True)
...    try:
...        acct.full_clean()
...        print(acct.iban)
...    except ValidationError:
...        pass
>>> for i in ibans:
...    print_if_good(i)