From 4c97f4cb48db8ecfda06a351f9b5ef81cdf52d97 Mon Sep 17 00:00:00 2001 From: James Jesudason Date: Wed, 11 Jan 2012 18:21:15 +0000 Subject: [PATCH] Use the SWIFT code as the default account code format --- account_banking_uk_hsbc/wizard/export_hsbc.py | 25 ++++++++-- account_banking_uk_hsbc/wizard/paymul.py | 48 +++++++++++++++++++ 2 files changed, 69 insertions(+), 4 deletions(-) diff --git a/account_banking_uk_hsbc/wizard/export_hsbc.py b/account_banking_uk_hsbc/wizard/export_hsbc.py index eb252ca94..72ffe43e9 100644 --- a/account_banking_uk_hsbc/wizard/export_hsbc.py +++ b/account_banking_uk_hsbc/wizard/export_hsbc.py @@ -202,11 +202,28 @@ class banking_export_hsbc_wizard(osv.osv_memory): 'charges': paymul.CHARGES_PAYEE, } else: - self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'Unsupported Account: %s' % (oe_account.country_id.code)) - raise osv.except_osv( - _('Error'), - _('%s: only UK, US, Canada accounts and IBAN are supported') % (holder) + self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'SWIFT Account: %s' % (oe_account.country_id.code)) + split = oe_account.acc_number.split(' ', 2) + if len(split) == 2: + sortcode, accountno = split + else: + raise osv.except_osv( + _('Error'), + "Invalid %s account number '%s'" % (oe_account.country_id.code,oe_account.acc_number)) + paymul_account = paymul.SWIFTAccount( + number=accountno, + sortcode=sortcode, + holder=holder, + currency=currency, + swiftcode=oe_account.bank.bic, + country=oe_account.country_id.code, ) + transaction_kwargs = { + 'charges': paymul.CHARGES_PAYEE, + } + transaction_kwargs = { + 'charges': paymul.CHARGES_PAYEE, + } return paymul_account, transaction_kwargs diff --git a/account_banking_uk_hsbc/wizard/paymul.py b/account_banking_uk_hsbc/wizard/paymul.py index 599a615e4..d1b16a9a4 100644 --- a/account_banking_uk_hsbc/wizard/paymul.py +++ b/account_banking_uk_hsbc/wizard/paymul.py @@ -224,6 +224,54 @@ class NorthAmericanAccount(UKAccount): self.institution_identification = self._set_account_ident() +class SWIFTAccount(UKAccount): + + def _set_account_ident(self): + # Using the BIC/Swift Code + return [self.bic, 25, 5, '', '', ''] + + def _set_sortcode(self, sortcode): + self._sortcode = sortcode + + def _get_sortcode(self): + return self._sortcode + + sortcode = property(_get_sortcode, _set_sortcode) + + def _set_bic(self, bic): + if not edifact_isalnum_size(bic, 8) and not edifact_isalnum_size(bic, 11): + raise ValueError("Account BIC/Swift code must be 8 or 11 characters long: " + + str(bic)) + self._bic = bic + + def _get_bic(self): + return self._bic + + bic = property(_get_bic, _set_bic) + + def _set_number(self, number): + if not edifact_digits(number, mindigits=1): + raise ValueError("Account number is invalid: " + + str(number)) + + self._number = number + + def _get_number(self): + return self._number + + number = property(_get_number, _set_number) + + def __init__(self, number, holder, currency, sortcode, swiftcode, country, origin_country=None): + self.number = number + self.holder = holder + self.currency = currency + self.sortcode = sortcode + self.country = country + self.bic = swiftcode + self.origin_country = origin_country + self.institution_identification = self._set_account_ident() + + class IBANAccount(HasCurrency): def _get_iban(self): return self._iban