mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[IMP] ABN-AMRO: process SEPA feedback string
[IMP] Framework: use bic info from transaction if available when creating bank
This commit is contained in:
@@ -1319,7 +1319,8 @@ class banking_import_transaction(osv.osv):
|
||||
transaction.remote_owner,
|
||||
transaction.remote_owner_address,
|
||||
transaction.remote_owner_city,
|
||||
country_code, results['log']
|
||||
country_code, results['log'],
|
||||
bic=transaction.remote_bank_bic
|
||||
)
|
||||
partner_banks = partner_bank_obj.browse(
|
||||
cr, uid, [partner_bank_id]
|
||||
|
||||
@@ -318,7 +318,7 @@ def get_or_create_bank(pool, cursor, uid, bic, online=False, code=None,
|
||||
|
||||
def create_bank_account(pool, cursor, uid, partner_id,
|
||||
account_number, holder_name, address, city,
|
||||
country_code, log
|
||||
country_code, log, bic=False,
|
||||
):
|
||||
'''
|
||||
Create a matching bank account with this holder for this partner.
|
||||
@@ -328,7 +328,6 @@ def create_bank_account(pool, cursor, uid, partner_id,
|
||||
owner_name = holder_name,
|
||||
)
|
||||
bankcode = None
|
||||
bic = None
|
||||
country_obj = pool.get('res.country')
|
||||
|
||||
# Are we dealing with IBAN?
|
||||
|
||||
@@ -88,6 +88,7 @@ class transaction(models.mem_bank_transaction):
|
||||
'GIRO': bt.ORDER,
|
||||
'INTL': bt.ORDER, # international order
|
||||
'UNKN': bt.ORDER, # everything else
|
||||
'SEPA': bt.ORDER,
|
||||
}
|
||||
|
||||
def __init__(self, line, *args, **kwargs):
|
||||
@@ -134,18 +135,34 @@ class transaction(models.mem_bank_transaction):
|
||||
size = 33
|
||||
res = []
|
||||
while(len(line) > col * size):
|
||||
if line[col * size : (col + 1) * size - 1].strip():
|
||||
res.append(line[col * size : (col + 1) * size - 1])
|
||||
separation = (col + 1) * size - 1
|
||||
if line[col * size : separation].strip():
|
||||
part = line[col * size : separation]
|
||||
# If the separation character is not a space, add it anyway
|
||||
# presumably for sepa feedback strings only
|
||||
if (len(line) > separation
|
||||
and line[separation] != ' '):
|
||||
part += line[separation]
|
||||
res.append(part)
|
||||
col += 1
|
||||
return res
|
||||
|
||||
def get_sepa_dict(field):
|
||||
items = field[1:].split('/') # skip leading slash
|
||||
sepa_dict = {}
|
||||
while items:
|
||||
sepa_dict[items.pop(0)] = items.pop(1).strip()
|
||||
return sepa_dict
|
||||
|
||||
def parse_type(field):
|
||||
# here we process the first field, which identifies the statement type
|
||||
# and in case of certain types contains additional information
|
||||
transfer_type = 'UNKN'
|
||||
remote_account = False
|
||||
remote_owner = False
|
||||
if field.startswith('GIRO '):
|
||||
if field.startswith('/TRTP/'):
|
||||
transfer_type = 'SEPA'
|
||||
elif field.startswith('GIRO '):
|
||||
transfer_type = 'GIRO'
|
||||
# columns 6 to 14 contain the left or right aligned account number
|
||||
remote_account = field[:15].strip().zfill(10)
|
||||
@@ -176,8 +193,18 @@ class transaction(models.mem_bank_transaction):
|
||||
fields = split_blob(self.blob)
|
||||
(self.transfer_type, self.remote_account, self.remote_owner) = parse_type(fields[0])
|
||||
|
||||
if self.transfer_type == 'SEPA':
|
||||
sepa_dict = get_sepa_dict(''.join(fields))
|
||||
sepa_type = sepa_dict.get('TRTP')
|
||||
if sepa_type != 'SEPA OVERBOEKING':
|
||||
raise ValueError,_('Sepa transaction type %s not handled yet')
|
||||
self.remote_account = sepa_dict.get('IBAN',False)
|
||||
self.remote_bank_bic = sepa_dict.get('BIC', False)
|
||||
self.remote_owner = sepa_dict.get('NAME', False)
|
||||
self.reference = sepa_dict.get('REMI', False)
|
||||
|
||||
# extract other information depending on type
|
||||
if self.transfer_type == 'GIRO':
|
||||
elif self.transfer_type == 'GIRO':
|
||||
self.message = ' '.join(field.strip() for field in fields[1:])
|
||||
|
||||
elif self.transfer_type == 'BEA':
|
||||
|
||||
Reference in New Issue
Block a user