changeset b1dd3c2696de in modules/bank:6.4
details: https://hg.tryton.org/modules/bank?cmd=changeset&node=b1dd3c2696de
description:
Do not fail to compute number record name without bank
and do not fail to guess bank without IBAN.
issue11487
review431111003
(grafted from 3c4689e449e5f7cde46f2f188380bf155df49096)
diffstat:
bank.py | 13 +++++---
tests/test_module.py | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 81 insertions(+), 5 deletions(-)
diffs (127 lines):
diff -r e845fb1b8704 -r b1dd3c2696de bank.py
--- a/bank.py Mon May 02 16:46:22 2022 +0200
+++ b/bank.py Tue May 31 23:53:01 2022 +0200
@@ -97,11 +97,14 @@
help="Add the numbers which identify the bank account.")
def get_rec_name(self, name):
- if self.numbers:
- number = self.numbers[0].number
+ for number in self.numbers:
+ if number.number:
+ name = number.number
+ break
else:
- number = '(%s)' % self.id
- name = '%s @ %s' % (number, self.bank.rec_name)
+ name = '(%s)' % self.id
+ if self.bank:
+ name += ' @ %s' % self.bank.rec_name
if self.currency:
name += ' [%s]' % self.currency.code
return name
@@ -155,7 +158,7 @@
def guess_bank(self):
pool = Pool()
Bank = pool.get('bank')
- if IBAN:
+ if IBAN and self.iban:
iban = IBAN(self.iban)
if iban.bic:
return Bank.from_bic(iban.bic)
diff -r e845fb1b8704 -r b1dd3c2696de tests/test_module.py
--- a/tests/test_module.py Mon May 02 16:46:22 2022 +0200
+++ b/tests/test_module.py Tue May 31 23:53:01 2022 +0200
@@ -10,6 +10,7 @@
from trytond.model.exceptions import SQLConstraintError
from trytond.modules.bank.exceptions import InvalidBIC
+from trytond.modules.currency.tests import create_currency
from trytond.pool import Pool
from trytond.tests.test_tryton import ModuleTestCase, with_transaction
@@ -89,6 +90,65 @@
self.assertEqual(other_number.number, 'BE82068896274468')
@with_transaction()
+ def test_account_rec_name_without_number(self):
+ "Test account record name without number"
+ pool = Pool()
+ Account = pool.get('bank.account')
+
+ account = Account()
+ account.save()
+
+ self.assertEqual(account.rec_name, "(%s)" % account.id)
+
+ @with_transaction()
+ def test_account_rec_name_with_number(self):
+ "Test account record name with number"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Number = pool.get('bank.account.number')
+
+ account = Account(numbers=[
+ Number(type='other', number="1234")])
+ account.save()
+
+ self.assertEqual(account.rec_name, "1234")
+
+ @with_transaction()
+ def test_account_rec_name_with_bank(self):
+ "Test account record name with bank"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Bank = pool.get('bank')
+ Number = pool.get('bank.account.number')
+ Party = pool.get('party.party')
+
+ party = Party(name="Bank")
+ party.save()
+ bank = Bank(party=party)
+ bank.save()
+ account = Account(
+ numbers=[Number(type='other', number="1234")],
+ bank=bank)
+ account.save()
+
+ self.assertEqual(account.rec_name, "1234 @ Bank")
+
+ @with_transaction()
+ def test_account_rec_name_with_currency(self):
+ "Test account record name with currency"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Number = pool.get('bank.account.number')
+
+ currency = create_currency("USD")
+ account = Account(
+ numbers=[Number(type='other', number="1234")],
+ currency=currency)
+ account.save()
+
+ self.assertEqual(account.rec_name, "1234 [USD]")
+
+ @with_transaction()
def test_number_single_iban(self):
"Test number has single IBAN"
pool = Pool()
@@ -155,5 +215,18 @@
self.assertEqual(len(Bank.search([])), 1)
+ @with_transaction()
+ def test_guess_bank_without_iban(self):
+ "Test guess bank without IBAN"
+ pool = Pool()
+ Account = pool.get('bank.account')
+ Number = pool.get('bank.account.number')
+
+ account = Account(numbers=[
+ Number(type='other', number="123456")])
+ account.save()
+
+ self.assertIsNone(account.bank)
+
del ModuleTestCase