Merge lp:~therp-nl/banking-addons/6.1-no_unnecessary_raise into lp:banking-addons/6.1

Proposed by Stefan Rijnhart (Opener)
Status: Merged
Merged at revision: 194
Proposed branch: lp:~therp-nl/banking-addons/6.1-no_unnecessary_raise
Merge into: lp:banking-addons/6.1
Diff against target: 149 lines (+42/-49)
3 files modified
account_banking/account_banking.py (+36/-42)
account_banking/sepa/iban.py (+3/-4)
account_banking/sepa/online.py (+3/-3)
To merge this branch: bzr merge lp:~therp-nl/banking-addons/6.1-no_unnecessary_raise
Reviewer Review Type Date Requested Status
Holger Brunn (Therp) code review Approve
Yannick Vaucher @ Camptocamp code review, no tests Approve
Review via email: mp+205647@code.launchpad.net

Description of the change

Legacy code raises in two instances:
- When the BBAN of a Turkish IBAN is requested
- When no online database lookup is implemented for a region

These exceptions were not caught properly in every case. Instead of adding additional try/except blocks, I'm proposing to do away with these exceptions and return False instead. Dealing with an empty value is obvious in all cases where these methods are called.

7.0 version here: https://code.launchpad.net/~therp-nl/banking-addons/7.0-no_unnecessary_raise/+merge/205648

To post a comment you must log in.
Revision history for this message
Yannick Vaucher @ Camptocamp (yvaucher-c2c) wrote :

LGTM

review: Approve (code review, no tests)
Revision history for this message
Holger Brunn (Therp) (hbrunn) wrote :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account_banking/account_banking.py'
--- account_banking/account_banking.py 2013-12-13 10:45:24 +0000
+++ account_banking/account_banking.py 2014-02-10 20:23:17 +0000
@@ -1321,14 +1321,10 @@
1321 if term[0].lower() == 'acc_number' and term[1] in ('=', '=='):1321 if term[0].lower() == 'acc_number' and term[1] in ('=', '=='):
1322 iban = sepa.IBAN(term[2])1322 iban = sepa.IBAN(term[2])
1323 if iban.valid:1323 if iban.valid:
1324 # Some countries can't convert to BBAN1324 bban = iban.localized_BBAN
1325 try:1325 # Prevent empty search filters
1326 bban = iban.localized_BBAN1326 if bban:
1327 # Prevent empty search filters1327 extra_term = ('acc_number_domestic', term[1], bban)
1328 if bban:
1329 extra_term = ('acc_number_domestic', term[1], bban)
1330 except:
1331 pass
1332 if extra_term:1328 if extra_term:
1333 return ['|', term, extra_term]1329 return ['|', term, extra_term]
1334 return [term]1330 return [term]
@@ -1404,10 +1400,7 @@
1404 res[record.id] = False1400 res[record.id] = False
1405 else:1401 else:
1406 iban_acc = sepa.IBAN(record.acc_number)1402 iban_acc = sepa.IBAN(record.acc_number)
1407 try:1403 res[record.id] = iban_acc.localized_BBAN
1408 res[record.id] = iban_acc.localized_BBAN
1409 except NotImplementedError:
1410 res[record.id] = False
1411 return res1404 return res
14121405
1413 def onchange_acc_number(1406 def onchange_acc_number(
@@ -1491,44 +1484,45 @@
1491 country = country_obj.browse(1484 country = country_obj.browse(
1492 cursor, uid, country_ids[0], context=context)1485 cursor, uid, country_ids[0], context=context)
1493 if country and country.code in sepa.IBAN.countries:1486 if country and country.code in sepa.IBAN.countries:
1494 try:1487 info = sepa.online.account_info(country.code, acc_number)
1495 info = sepa.online.account_info(country.code, acc_number)1488 if info:
1496 if info:1489 iban_acc = sepa.IBAN(info.iban)
1497 iban_acc = sepa.IBAN(info.iban)1490 if iban_acc.valid:
1498 if iban_acc.valid:1491 values['acc_number_domestic'] = iban_acc.localized_BBAN
1499 values['acc_number_domestic'] = iban_acc.localized_BBAN1492 values['acc_number'] = unicode(iban_acc)
1500 values['acc_number'] = unicode(iban_acc)1493 values['state'] = 'iban'
1501 values['state'] = 'iban'1494 bank_id, country_id = get_or_create_bank(
1502 bank_id, country_id = get_or_create_bank(1495 self.pool, cursor, uid,
1503 self.pool, cursor, uid,1496 info.bic or iban_acc.BIC_searchkey,
1504 info.bic or iban_acc.BIC_searchkey,1497 name = info.bank
1505 name = info.bank1498 )
1506 )1499 values['country_id'] = country_id or \
1507 values['country_id'] = country_id or \1500 country_ids and country_ids[0] or \
1508 country_ids and country_ids[0] or \1501 False
1509 False1502 values['bank'] = bank_id or False
1510 values['bank'] = bank_id or False1503 if info.bic:
1511 if info.bic:1504 values['bank_bic'] = info.bic
1512 values['bank_bic'] = info.bic1505 else:
1513 else:1506 info = None
1514 info = None1507 if info is None:
1515 if info is None:1508 result.update(warning(
1516 result.update(warning(
1517 _('Invalid data'),1509 _('Invalid data'),
1518 _('The account number appears to be invalid for %(country)s')1510 _('The account number appears to be invalid for '
1511 '%(country)s')
1519 % {'country': country.name}1512 % {'country': country.name}
1520 ))1513 ))
1521 except NotImplementedError:1514 if info is False:
1522 if country.code in sepa.IBAN.countries:1515 if country.code in sepa.IBAN.countries:
1523 acc_number_fmt = sepa.BBAN(acc_number, country.code)1516 acc_number_fmt = sepa.BBAN(acc_number, country.code)
1524 if acc_number_fmt.valid:1517 if acc_number_fmt.valid:
1525 values['acc_number_domestic'] = str(acc_number_fmt)1518 values['acc_number_domestic'] = str(acc_number_fmt)
1526 else:1519 else:
1527 result.update(warning(1520 result.update(warning(
1528 _('Invalid format'),1521 _('Invalid format'),
1529 _('The account number has the wrong format for %(country)s')1522 _('The account number has the wrong format '
1530 % {'country': country.name}1523 'for %(country)s')
1531 ))1524 % {'country': country.name}
1525 ))
1532 return result1526 return result
15331527
1534 def onchange_iban(1528 def onchange_iban(
15351529
=== modified file 'account_banking/sepa/iban.py'
--- account_banking/sepa/iban.py 2013-10-14 12:30:40 +0000
+++ account_banking/sepa/iban.py 2014-02-10 20:23:17 +0000
@@ -408,10 +408,9 @@
408 Localized format of local or Basic Bank Account Number, aka BBAN408 Localized format of local or Basic Bank Account Number, aka BBAN
409 '''409 '''
410 if self.countrycode == 'TR':410 if self.countrycode == 'TR':
411 raise NotImplementedError, (411 # The Turkish BBAN requires information that is not in the
412 'The Turkish BBAN requires information that is not in the '412 # IBAN number.
413 'IBAN number.'413 return False
414 )
415 return self.BBAN_format.BBAN(self)414 return self.BBAN_format.BBAN(self)
416415
417 @property416 @property
418417
=== modified file 'account_banking/sepa/online.py'
--- account_banking/sepa/online.py 2012-01-12 09:50:06 +0000
+++ account_banking/sepa/online.py 2014-02-10 20:23:17 +0000
@@ -157,13 +157,13 @@
157 '''157 '''
158 Consult the online database for this country to obtain its158 Consult the online database for this country to obtain its
159 corresponding IBAN/BIC number and other info available.159 corresponding IBAN/BIC number and other info available.
160 Raise NotImplemented when no information service could be found.
161 Returns None when a service was found but something went wrong.160 Returns None when a service was found but something went wrong.
162 Returns a dictionary (struct) of information when found.161 Returns a dictionary (struct) of information when found, or
162 False when not implemented.
163 '''163 '''
164 if iso in _account_info:164 if iso in _account_info:
165 return _account_info[iso](bank_acc)165 return _account_info[iso](bank_acc)
166 raise NotImplementedError()166 return False
167167
168bic_re = re.compile("[^']+'([^']*)'.*")168bic_re = re.compile("[^']+'([^']*)'.*")
169SWIFTlink = 'http://www.swift.com/bsl/freequery.do'169SWIFTlink = 'http://www.swift.com/bsl/freequery.do'

Subscribers

People subscribed via source and target branches