mirror of
https://github.com/OCA/bank-payment.git
synced 2025-02-02 10:37:31 +02:00
Merge pull request #3 from StefanRijnhart/7.0-camt_improvements
7.0 camt improvements
This commit is contained in:
@@ -26,7 +26,7 @@
|
||||
|
||||
{
|
||||
'name': 'Account Banking',
|
||||
'version': '0.4',
|
||||
'version': '0.5',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'Banking addons community',
|
||||
'website': 'https://launchpad.net/banking-addons',
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
##############################################################################
|
||||
|
||||
import re
|
||||
from difflib import SequenceMatcher
|
||||
from openerp.tools.translate import _
|
||||
|
||||
|
||||
@@ -353,6 +354,24 @@ class parser(object):
|
||||
country_code = None
|
||||
doc = __doc__
|
||||
|
||||
def normalize_identifier(self, account, identifier):
|
||||
"""
|
||||
Strip any substantial part of the account number from
|
||||
the identifier, as well as the common prefix 'CAMT053'.
|
||||
"""
|
||||
if identifier.upper().startswith('CAMT053'):
|
||||
identifier = identifier[7:]
|
||||
seq_matcher = SequenceMatcher(None, account, identifier)
|
||||
_a, start, length = seq_matcher.find_longest_match(
|
||||
0, len(account), 0, len(identifier))
|
||||
if length < 7:
|
||||
return identifier
|
||||
result = identifier[0:start] + \
|
||||
identifier[start + length:len(identifier)]
|
||||
while result and not result[0].isalnum():
|
||||
result = result[1:]
|
||||
return result
|
||||
|
||||
def get_unique_statement_id(self, cr, base):
|
||||
name = base
|
||||
suffix = 1
|
||||
|
||||
@@ -32,6 +32,8 @@ use parser.models as a mean of communication with the business logic.
|
||||
|
||||
import base64
|
||||
import datetime
|
||||
from StringIO import StringIO
|
||||
from zipfile import ZipFile, BadZipfile # BadZipFile in Python >= 3.2
|
||||
from openerp.osv import orm, fields
|
||||
from openerp.tools.translate import _
|
||||
from openerp.addons.account_banking.parsers import models
|
||||
@@ -122,6 +124,15 @@ class banking_import(orm.TransientModel):
|
||||
banking_import = self.browse(cr, uid, ids, context)[0]
|
||||
statements_file = banking_import.file
|
||||
data = base64.decodestring(statements_file)
|
||||
files = [data]
|
||||
try:
|
||||
with ZipFile(StringIO(data), 'r') as archive:
|
||||
files = [
|
||||
archive.read(filename) for filename in archive.namelist()
|
||||
if not filename.endswith('/')
|
||||
]
|
||||
except BadZipfile:
|
||||
pass
|
||||
|
||||
user_obj = self.pool.get('res.user')
|
||||
statement_obj = self.pool.get('account.bank.statement')
|
||||
@@ -144,8 +155,10 @@ class banking_import(orm.TransientModel):
|
||||
company = (banking_import.company or
|
||||
user_obj.browse(cr, uid, uid, context).company_id)
|
||||
|
||||
# Parse the file
|
||||
statements = parser.parse(cr, data)
|
||||
# Parse the file(s)
|
||||
statements = []
|
||||
for import_file in files:
|
||||
statements += parser.parse(cr, import_file)
|
||||
|
||||
if any([x for x in statements if not x.is_valid()]):
|
||||
raise orm.except_orm(
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
##############################################################################
|
||||
{
|
||||
'name': 'CAMT Format Bank Statements Import',
|
||||
'version': '0.1',
|
||||
'version': '0.2',
|
||||
'license': 'AGPL-3',
|
||||
'author': 'Therp BV',
|
||||
'website': 'https://launchpad.net/banking-addons',
|
||||
|
||||
@@ -140,9 +140,9 @@ CAMT Format parser
|
||||
if self.xpath(node, './ns:Acct/ns:Id/ns:IBAN')
|
||||
else self.xpath(node, './ns:Acct/ns:Id/ns:Othr/ns:Id')[0].text)
|
||||
|
||||
identifier = node.find(self.ns + 'Id').text
|
||||
if identifier.upper().startswith('CAMT053'):
|
||||
identifier = identifier[7:]
|
||||
identifier = self.normalize_identifier(
|
||||
statement.local_account,
|
||||
node.find(self.ns + 'Id').text)
|
||||
statement.id = self.get_unique_statement_id(
|
||||
cr, "%s-%s" % (
|
||||
self.get_unique_account_identifier(
|
||||
@@ -199,6 +199,17 @@ CAMT Format parser
|
||||
vals = self.parse_TxDtls(TxDtls[0], entry_details)
|
||||
else:
|
||||
vals = entry_details
|
||||
# Append additional entry info, which can contain remittance
|
||||
# information in legacy format
|
||||
Addtl = self.find(node, './ns:AddtlNtryInf')
|
||||
if Addtl is not None and Addtl.text:
|
||||
if vals.get('message'):
|
||||
vals['message'] = '%s %s' % (vals['message'], Addtl.text)
|
||||
else:
|
||||
vals['message'] = Addtl.text
|
||||
# Promote the message to reference if we don't have one yet
|
||||
if not vals.get('reference') and vals.get('message'):
|
||||
vals['reference'] = vals['message']
|
||||
return vals
|
||||
|
||||
def get_party_values(self, TxDtls):
|
||||
|
||||
Reference in New Issue
Block a user