Handle payments from and to US/Canada bank accounts

This commit is contained in:
James Jesudason
2011-12-06 17:03:48 +00:00
parent ff4d0dd76f
commit f9a6089443
2 changed files with 73 additions and 0 deletions

View File

@@ -167,6 +167,29 @@ class banking_export_hsbc_wizard(osv.osv_memory):
transaction_kwargs = {
'charges': paymul.CHARGES_PAYEE,
}
elif oe_account.country_id.code in ('US','CA'):
split = oe_account.acc_number.split(' ', 2)
if len(split) == 2:
sortcode, accountno = split
else:
raise osv.except_osv(
_('Error'),
"Invalid %s acccount number '%s'" % (oe_account.country_id.code,oe_account.acc_number))
paymul_account = paymul.NorthAmericanAccount(
number=accountno,
sortcode=sortcode,
holder=holder,
currency=currency,
swiftcode=oe_account.bank.bic,
country=oe_account.country_id.code,
#origin_country=origin_country
)
transaction_kwargs = {
'charges': paymul.CHARGES_PAYEE,
}
transaction_kwargs = {
'charges': paymul.CHARGES_PAYEE,
}
else:
raise osv.except_osv(
_('Error'),

View File

@@ -47,6 +47,10 @@ def edifact_digits(val, digits, mindigits=None):
pattern = r'^[0-9]{' + str(mindigits) + ',' + str(digits) + r'}$'
return bool(re.match(pattern, str(val)))
def edifact_isalnum_size(val, digits):
pattern = r'^[A-Za-z0-9 ]{' + str(digits) + ',' + str(digits) + r'}$'
return bool(re.match(pattern, str(val)))
class HasCurrency(object):
def _get_currency(self):
return self._currency
@@ -155,6 +159,52 @@ class UKAccount(HasCurrency):
def fii_or_segment(self):
return _fii_segment(self, 'OR')
class NorthAmericanAccount(UKAccount):
def __init__(self, number, holder, currency, sortcode, swiftcode, country, origin_country=None):
super(NorthAmericanAccount,self).__init__(number, holder, currency, sortcode)
self.country = country
self.bic = swiftcode
self.origin_country = origin_country
self.institution_identification = self._set_account_ident()
def _set_account_ident(self):
if self.origin_country in ('US','CA'):
# Use the routing number
account_ident = ['', '', '', self.sortcode, 155, 114]
else:
# Using the BIC/Swift Code
account_ident = [self.bic, 25, 5, '', '', '']
return account_ident
def _set_sortcode(self, sortcode):
if not edifact_digits(sortcode, 9):
raise ValueError("Account routing number must be 9 digits long: " +
str(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)
class IBANAccount(HasCurrency):
def _get_iban(self):
return self._iban