Allow multi-currency payments in a single payment file and include logging

This commit is contained in:
James Jesudason
2012-01-05 14:08:10 +00:00
parent f9a6089443
commit 1f6a4d7e4c
2 changed files with 45 additions and 16 deletions

View File

@@ -28,6 +28,7 @@ from decimal import Decimal
import paymul
import string
import random
import netsvc
def strpdate(arg, format='%Y-%m-%d'):
'''shortcut'''
@@ -98,6 +99,8 @@ class banking_export_hsbc_wizard(osv.osv_memory):
),
}
logger = netsvc.Logger()
def create(self, cursor, uid, wizard_data, context=None):
'''
Retrieve a sane set of default values based on the payment orders
@@ -139,8 +142,14 @@ class banking_export_hsbc_wizard(osv.osv_memory):
def _create_account(self, oe_account):
currency = None # let the receiving bank select the currency from the batch
holder = oe_account.owner_name or oe_account.partner_id.name
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'Create account %s' % (holder))
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'-- %s' % (oe_account.country_id.code))
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'-- %s' % (oe_account.acc_number))
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'-- %s' % (oe_account.iban))
if oe_account.iban:
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'IBAN: %s' % (oe_account.iban))
paymul_account = paymul.IBANAccount(
iban=oe_account.iban,
bic=oe_account.bank.bic,
@@ -151,6 +160,7 @@ class banking_export_hsbc_wizard(osv.osv_memory):
'charges': paymul.CHARGES_EACH_OWN,
}
elif oe_account.country_id.code == 'GB':
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'GB: %s %s' % (oe_account.country_id.code,oe_account.acc_number))
split = oe_account.acc_number.split(" ", 2)
if len(split) == 2:
sortcode, accountno = split
@@ -168,13 +178,14 @@ class banking_export_hsbc_wizard(osv.osv_memory):
'charges': paymul.CHARGES_PAYEE,
}
elif oe_account.country_id.code in ('US','CA'):
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'US/CA: %s %s' % (oe_account.country_id.code,oe_account.acc_number))
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))
"Invalid %s account number '%s'" % (oe_account.country_id.code,oe_account.acc_number))
paymul_account = paymul.NorthAmericanAccount(
number=accountno,
sortcode=sortcode,
@@ -191,9 +202,10 @@ 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 accounts and IBAN are supported') % (holder)
_('%s: only UK, US, Canada accounts and IBAN are supported') % (holder)
)
return paymul_account, transaction_kwargs
@@ -208,7 +220,8 @@ class banking_export_hsbc_wizard(osv.osv_memory):
'number must be provided'
)
)
self.logger.notifyChannel('paymul', netsvc.LOG_INFO, '====')
dest_account, transaction_kwargs = self._create_account(line.bank_id)
means = {'ACH or EZONE': paymul.MEANS_ACH_OR_EZONE,
@@ -244,6 +257,7 @@ class banking_export_hsbc_wizard(osv.osv_memory):
try:
self.logger.notifyChannel('paymul', netsvc.LOG_INFO,'Source - %s (%s) %s' % (payment_orders[0].mode.bank_id.partner_id.name, payment_orders[0].mode.bank_id.acc_number, payment_orders[0].mode.bank_id.country_id.code))
src_account = self._create_account(
payment_orders[0].mode.bank_id,
)[0]
@@ -260,6 +274,7 @@ class banking_export_hsbc_wizard(osv.osv_memory):
"account number (not IBAN)" + str(type(src_account)))
)
self.logger.notifyChannel('paymul', netsvc.LOG_INFO, 'Create transactions...')
transactions = []
for po in payment_orders:
transactions += [self._create_transaction(l) for l in po.line_ids]

View File

@@ -162,13 +162,6 @@ class UKAccount(HasCurrency):
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
@@ -202,7 +195,28 @@ class NorthAmericanAccount(UKAccount):
bic = property(_get_bic, _set_bic)
def _set_number(self, number):
if not edifact_digits(number, 9):
raise ValueError("Account number must be 9 digits long: " +
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):
#super(NorthAmericanAccount,self).__init__(number, holder, currency, sortcode)
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):
@@ -374,13 +388,13 @@ class Batch(LogicalSection):
])
currencies = set([x.currency for x in self.transactions])
if len(currencies) > 1:
raise ValueError("All transactions in a batch must have the same currency")
#if len(currencies) > 1:
# raise ValueError("All transactions in a batch must have the same currency")
segments.append([
['MOA'],
[9, self.amount().quantize(Decimal('0.00')), currencies.pop()],
])
#segments.append([
# ['MOA'],
# [9, self.amount().quantize(Decimal('0.00')), currencies.pop()],
#])
segments.append(self.debit_account.fii_or_segment())
segments.append([
['NAD'],