clearcorp team mailing list archive
-
clearcorp team
-
Mailing list archive
-
Message #00460
[Branch ~banking-addons-team/banking-addons/6.1] Rev 147: [IMP] ABN-AMRO: process SEPA feedback string
Merge authors:
Stefan Rijnhart (Therp) (stefan-therp)
Related merge proposals:
https://code.launchpad.net/~therp-nl/banking-addons/6.1-abnamro_process_sepa_feedback_string/+merge/128696
proposed by: Stefan Rijnhart (Therp) (stefan-therp)
review: Approve - Guewen Baconnier @ Camptocamp (gbaconnier-c2c)
------------------------------------------------------------
revno: 147 [merge]
author: Stefan Rijnhart <stefan@xxxxxxxx>
committer: Guewen Baconnier @ Camptocamp <guewen.baconnier@xxxxxxxxxxxxxx>
branch nick: banking-addons
timestamp: Tue 2012-12-18 15:41:15 +0100
message:
[IMP] ABN-AMRO: process SEPA feedback string
[IMP] Framework: use bic info from transaction if available when creating bank
modified:
account_banking/banking_import_transaction.py
account_banking/wizard/banktools.py
account_banking_nl_abnamro/abnamro.py
--
lp:banking-addons
https://code.launchpad.net/~banking-addons-team/banking-addons/6.1
Your team CLEARCORP development team is subscribed to branch lp:banking-addons.
To unsubscribe from this branch go to https://code.launchpad.net/~banking-addons-team/banking-addons/6.1/+edit-subscription
=== modified file 'account_banking/banking_import_transaction.py'
--- account_banking/banking_import_transaction.py 2012-12-18 14:39:59 +0000
+++ account_banking/banking_import_transaction.py 2012-12-18 14:41:15 +0000
@@ -1323,7 +1323,8 @@
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]
=== modified file 'account_banking/wizard/banktools.py'
--- account_banking/wizard/banktools.py 2012-12-05 07:22:19 +0000
+++ account_banking/wizard/banktools.py 2012-12-18 14:41:15 +0000
@@ -320,7 +320,7 @@
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.
@@ -330,7 +330,6 @@
owner_name = holder_name,
)
bankcode = None
- bic = None
country_obj = pool.get('res.country')
# Are we dealing with IBAN?
=== modified file 'account_banking_nl_abnamro/abnamro.py'
--- account_banking_nl_abnamro/abnamro.py 2012-01-17 08:48:10 +0000
+++ account_banking_nl_abnamro/abnamro.py 2012-10-27 19:53:50 +0000
@@ -88,6 +88,7 @@
'GIRO': bt.ORDER,
'INTL': bt.ORDER, # international order
'UNKN': bt.ORDER, # everything else
+ 'SEPA': bt.ORDER,
}
def __init__(self, line, *args, **kwargs):
@@ -134,24 +135,70 @@
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):
+ """
+ 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
+ sepa_dict = {}
+ prev_key = False
+ known_keys = ['TRTP', 'IBAN', 'BIC', 'NAME', 'RTRN', 'EREF',
+ 'SWOC', 'REMI', ]
+ while items:
+ 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
+
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)
- # column 15 contains a space
- # columns 16 to 31 contain remote owner
- remote_owner = field[16:32].strip() or False
+ # field has markup 'GIRO ACCOUNT OWNER'
+ # separated by clusters of space of varying size
+ account_match = re.match('\s*([0-9]+)\s(.*)$', field[5:])
+ if account_match:
+ remote_account = account_match.group(1).zfill(10)
+ remote_owner = account_match.group(2).strip() or ''
+ else:
+ raise osv.except_osv(
+ _('Error !'),
+ _('unable to parse GIRO string: %s') % field)
elif field.startswith('BEA '):
transfer_type = 'BEA'
# columns 6 to 16 contain the terminal identifier
@@ -176,8 +223,22 @@
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', '')
+
# extract other information depending on type
- if self.transfer_type == 'GIRO':
+ elif self.transfer_type == 'GIRO':
+ if not self.remote_owner and len(fields) > 1:
+ # OWNER is listed in the second field if not in the first
+ self.remote_owner = fields[1].strip() or False
+ fields = [fields[0]] + fields[2:]
self.message = ' '.join(field.strip() for field in fields[1:])
elif self.transfer_type == 'BEA':
@@ -219,11 +280,12 @@
if not self.reference:
# the reference is sometimes flagged by the prefix "BETALINGSKENM."
# but can be any numeric line really
- refexpr = re.compile("^\s*(BETALINGSKENM\.)?\s*([0-9]+ ?)+\s*$")
for field in fields[1:]:
- m = refexpr.match(field)
+ m = re.match(
+ "^\s*((BETALINGSKENM\.)|(ACCEPTGIRO))?\s*([0-9]+([ /][0-9]+)*)\s*$",
+ field)
if m:
- self.reference = m.group(2)
+ self.reference = m.group(4)
break
class statement(models.mem_bank_statement):