mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
[RFR] SEPA message string parts is known to contain its own separator
This commit is contained in:
@@ -148,10 +148,35 @@ class transaction(models.mem_bank_transaction):
|
|||||||
return res
|
return res
|
||||||
|
|
||||||
def get_sepa_dict(field):
|
def get_sepa_dict(field):
|
||||||
|
"""
|
||||||
|
Parses a subset of SEPA feedback strings as occur
|
||||||
|
in this non-SEPA csv format.
|
||||||
|
|
||||||
|
The string consists of slash separated KEY/VALUE pairs,
|
||||||
|
but the slash is allowed to and known to occur in VALUE as well!
|
||||||
|
"""
|
||||||
items = field[1:].split('/') # skip leading slash
|
items = field[1:].split('/') # skip leading slash
|
||||||
sepa_dict = {}
|
sepa_dict = {}
|
||||||
|
prev_key = False
|
||||||
|
known_keys = ['TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF',
|
||||||
|
'SWOC', 'REMI', ]
|
||||||
while items:
|
while items:
|
||||||
sepa_dict[items.pop(0)] = items.pop(1).strip()
|
if len(items) == 1:
|
||||||
|
raise osv.except_osv(
|
||||||
|
_('Error !'),
|
||||||
|
_("unable to parse SEPA string: %s") % field)
|
||||||
|
key = items.pop(0)
|
||||||
|
if key not in known_keys:
|
||||||
|
# either an unknown key or a value containing a slash
|
||||||
|
if prev_key:
|
||||||
|
sepa_dict[prev_key] = sepa_dict[prev_key] + '/' + key
|
||||||
|
else:
|
||||||
|
raise osv.except_osv(
|
||||||
|
_('Error !'),
|
||||||
|
_("unable to parse SEPA string: %s") % field)
|
||||||
|
else:
|
||||||
|
sepa_dict[key] = items.pop(0).strip()
|
||||||
|
prev_key = key
|
||||||
return sepa_dict
|
return sepa_dict
|
||||||
|
|
||||||
def parse_type(field):
|
def parse_type(field):
|
||||||
@@ -201,7 +226,7 @@ class transaction(models.mem_bank_transaction):
|
|||||||
self.remote_account = sepa_dict.get('IBAN',False)
|
self.remote_account = sepa_dict.get('IBAN',False)
|
||||||
self.remote_bank_bic = sepa_dict.get('BIC', False)
|
self.remote_bank_bic = sepa_dict.get('BIC', False)
|
||||||
self.remote_owner = sepa_dict.get('NAME', False)
|
self.remote_owner = sepa_dict.get('NAME', False)
|
||||||
self.reference = sepa_dict.get('REMI', False)
|
self.reference = sepa_dict.get('REMI', '')
|
||||||
|
|
||||||
# extract other information depending on type
|
# extract other information depending on type
|
||||||
elif self.transfer_type == 'GIRO':
|
elif self.transfer_type == 'GIRO':
|
||||||
|
|||||||
Reference in New Issue
Block a user