This commit is contained in:
2026-08-04 15:36:56 +02:00
parent 7fcc90d0a4
commit 7d7bd33b97
2 changed files with 24 additions and 1 deletions

View File

@@ -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)

View File

@@ -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'