IBAN
This commit is contained in:
@@ -133,6 +133,19 @@ class Account(DeactivableMixin, ModelSQL, ModelView):
|
||||
if number.type == 'iban':
|
||||
return number.number
|
||||
|
||||
@staticmethod
|
||||
def _bic_compact(bic):
|
||||
return getattr(bic, 'compact', bic)
|
||||
|
||||
@classmethod
|
||||
def _bic_matches(cls, first, second):
|
||||
def normalize(value):
|
||||
value = cls._bic_compact(value)
|
||||
if len(value) == 11 and value.endswith('XXX'):
|
||||
value = value[:8]
|
||||
return value
|
||||
return normalize(first) == normalize(second)
|
||||
|
||||
@classmethod
|
||||
def validate(cls, accounts):
|
||||
super().validate(accounts)
|
||||
@@ -146,7 +159,7 @@ class Account(DeactivableMixin, ModelSQL, ModelView):
|
||||
iban = IBAN(self.iban)
|
||||
bic = BIC(self.bank.bic)
|
||||
if (iban.bic
|
||||
and iban.bic != bic
|
||||
and not self._bic_matches(iban.bic, bic)
|
||||
and (
|
||||
iban.country_code != bic.country_code
|
||||
or (iban.bank_code or iban.branch_code)
|
||||
|
||||
@@ -41,6 +41,16 @@ class BankTestCase(ModuleTestCase):
|
||||
bank.bic = 'foo'
|
||||
bank.save()
|
||||
|
||||
@with_transaction()
|
||||
def test_bic_matches_primary_branch(self):
|
||||
"Test BIC matches main branch"
|
||||
pool = Pool()
|
||||
Account = pool.get('bank.account')
|
||||
|
||||
self.assertTrue(Account._bic_matches('CIALCHBBXXX', 'CIALCHBB'))
|
||||
self.assertTrue(Account._bic_matches('CIALCHBB', 'CIALCHBBXXX'))
|
||||
self.assertFalse(Account._bic_matches('CIALCHBB123', 'CIALCHBB'))
|
||||
|
||||
@with_transaction()
|
||||
def test_iban_format(self):
|
||||
'Test IBAN format'
|
||||
|
||||
Reference in New Issue
Block a user