Browse Source

iban is now more readable on bills

Jocelyn Delande 10 years ago
parent
commit
718aa15589

+ 3 - 1
coin/billing/templates/billing/payment_howto.html

@@ -1,9 +1,11 @@
+{% load isptags %}
+
 <p><strong>Merci de préférer si possible le paiement par virement</strong></p>
 
 <p>
 <strong>Virement</strong><br />
 Titulaire du compte : {{ branding.shortname|upper }}<br/>
-IBAN : {{ branding.bankinfo.iban }}<br />
+IBAN : {{ branding.bankinfo.iban|pretty_iban }}<br />
 
 {% if branding.bankinfo.bic %}
     BIC : {{ branding.bankinfo.bic }}<br />

+ 5 - 0
coin/isp_database/templatetags/isptags.py

@@ -5,3 +5,8 @@ register = Library()
 @register.inclusion_tag('isp_database/includes/isp_address_multiline.html')
 def multiline_isp_addr(branding):
     return {'branding': branding}
+
+@register.filter
+def pretty_iban(s):
+    #FR764 2559 0001 2410 2002 3285 19
+    return ' '.join([s[i:i+4] for i in xrange(0, len(s), 4)])

+ 15 - 0
coin/isp_database/tests.py

@@ -1,3 +1,18 @@
 from django.test import TestCase
 
 # Create your tests here.
+
+from coin.isp_database.templatetags.isptags import *
+
+class TestPrettifiers(TestCase):
+    def test_pretty_iban(self):
+        """ Prints pretty readable IBAN
+
+        Takes the IBAN in compact form and displays it according to the display spec
+        See http://en.wikipedia.org/wiki/International_Bank_Account_Number#Practicalities
+        """
+        self.assertEqual(pretty_iban('DEkkBBBBBBBBCCCCCCCCCC'),
+                         'DEkk BBBB BBBB CCCC CCCC CC')
+        self.assertEqual(pretty_iban('ADkkBBBBSSSSCCCCCCCCCCCC'),
+                         'ADkk BBBB SSSS CCCC CCCC CCCC')
+        self.assertEqual(pretty_iban(''), '')