diff --git a/modules/bank/bank.py b/modules/bank/bank.py index 7031663..c504099 100755 --- a/modules/bank/bank.py +++ b/modules/bank/bank.py @@ -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) diff --git a/modules/bank/tests/test_module.py b/modules/bank/tests/test_module.py index 7d600ea..d583c6e 100755 --- a/modules/bank/tests/test_module.py +++ b/modules/bank/tests/test_module.py @@ -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'