7.0 uk hsbc import improvements (#115)

* [IMP] hsbc mt940: ACH is a payment order type

* [FIX] hsbc mt940: Also include first info line in transaction description

* [IMP] hsbc mt940: Convert empty (NONREF) reference to blank

* [FIX] hsbc mt940: Allow ampersand character in alphanumeric fields

Although this is not mentioned in the official spec, it was found in
files generated by UK HSBC where a remote bank account name contained
an ampersand.
This commit is contained in:
Chris Halls
2018-04-29 01:27:26 +02:00
committed by Pedro M. Baeza
parent 8e63c287b7
commit aaf3c86b8f
2 changed files with 10 additions and 3 deletions

View File

@@ -45,13 +45,13 @@ class transaction(models.mem_bank_transaction):
'value_date': 'valuedate',
'local_currency': 'currency',
'transfer_type': 'bookingcode',
'reference': 'custrefno',
'message': 'furtherinfo'
}
type_map = {
'NTRF': bt.ORDER,
'NMSC': bt.ORDER,
'NACH': bt.ORDER,
'NPAY': bt.PAYMENT_BATCH,
'NCHK': bt.CHECK,
}
@@ -67,6 +67,10 @@ class transaction(models.mem_bank_transaction):
self.transferred_amount = record2float(record, 'amount')
ref = record.get('custrefno')
if ref and ref != 'NONREF':
self.reference = ref
# Set the transfer type based on the bookingcode
if record.get('bookingcode', 'ignore') in self.type_map:
self.transfer_type = self.type_map[record['bookingcode']]
@@ -151,7 +155,7 @@ class statement(models.mem_bank_statement):
record[k]
for k in (
'infoline{0}'.format(i)
for i in range(2, 5)
for i in range(1, 5)
)
if k in record
))

View File

@@ -35,7 +35,10 @@ class HSBCParser(object):
def __init__(self):
recparse = dict()
patterns = {'ebcdic': r"\w/\?:\(\).,'+{} -"}
# Allowed characters. The list was originally taken from HSBC's
# spec, but the ampersand character was found out in the wild in
# the customer account name
patterns = {'ebcdic': r"\w/\?:\(\).,'+{} &-"}
# MT940 header
recparse["20"] = r":(?P<recordid>20):(?P<transref>.{1,16})"