mirror of
https://github.com/OCA/bank-statement-import.git
synced 2025-01-20 12:37:43 +02:00
[ENH] Better separation of different MT940 types.
This commit is contained in:
@@ -101,7 +101,7 @@ class MT940(object):
|
|||||||
|
|
||||||
At least, you should override handle_tag_61 and handle_tag_86.
|
At least, you should override handle_tag_61 and handle_tag_86.
|
||||||
Don't forget to call super.
|
Don't forget to call super.
|
||||||
|
|
||||||
handle_tag_* functions receive the remainder of the the line (that is,
|
handle_tag_* functions receive the remainder of the the line (that is,
|
||||||
without ':XX:') and are supposed to write into self.current_transaction
|
without ':XX:') and are supposed to write into self.current_transaction
|
||||||
"""
|
"""
|
||||||
@@ -110,6 +110,7 @@ class MT940(object):
|
|||||||
"""Initialize parser - override at least header_regex.
|
"""Initialize parser - override at least header_regex.
|
||||||
|
|
||||||
This in fact uses the ING syntax, override in others."""
|
This in fact uses the ING syntax, override in others."""
|
||||||
|
self.mt940_type = 'General'
|
||||||
self.header_lines = 3 # Number of lines to skip
|
self.header_lines = 3 # Number of lines to skip
|
||||||
self.header_regex = '^{1:[0-9A-Z]{25,25}}' # Start of relevant data
|
self.header_regex = '^{1:[0-9A-Z]{25,25}}' # Start of relevant data
|
||||||
self.footer_regex = '^-}$|^-XXX$' # Stop processing on seeing this
|
self.footer_regex = '^-}$|^-XXX$' # Stop processing on seeing this
|
||||||
@@ -123,8 +124,8 @@ class MT940(object):
|
|||||||
if not bool(re.match(self.header_regex, line)):
|
if not bool(re.match(self.header_regex, line)):
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
'File starting with %s does not seem to be a'
|
'File starting with %s does not seem to be a'
|
||||||
' MT940 format bank statement.' %
|
' valid %s MT940 format bank statement.' %
|
||||||
data[:12]
|
(data[:12], self.mt940_type)
|
||||||
)
|
)
|
||||||
|
|
||||||
def parse(self, data):
|
def parse(self, data):
|
||||||
|
|||||||
@@ -33,6 +33,11 @@ class MT940Parser(MT940):
|
|||||||
r'(?P<reference>\w{1,50})'
|
r'(?P<reference>\w{1,50})'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""Initialize parser - override at least header_regex."""
|
||||||
|
super(MT940Parser, self).__init__()
|
||||||
|
self.mt940_type = 'ING'
|
||||||
|
|
||||||
def handle_tag_61(self, data):
|
def handle_tag_61(self, data):
|
||||||
"""get transaction values"""
|
"""get transaction values"""
|
||||||
super(MT940Parser, self).handle_tag_61(data)
|
super(MT940Parser, self).handle_tag_61(data)
|
||||||
|
|||||||
@@ -38,8 +38,8 @@ class MT940Parser(MT940):
|
|||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""Initialize parser - override at least header_regex."""
|
"""Initialize parser - override at least header_regex."""
|
||||||
super(MT940Parser, self).__init__()
|
super(MT940Parser, self).__init__()
|
||||||
|
self.mt940_type = 'RABO'
|
||||||
self.header_lines = 1 # Number of lines to skip
|
self.header_lines = 1 # Number of lines to skip
|
||||||
|
|
||||||
# Do not user $ for end of string below: line contains much
|
# Do not user $ for end of string below: line contains much
|
||||||
# more data than just the first line.
|
# more data than just the first line.
|
||||||
self.header_regex = '^:940:' # Start of relevant data
|
self.header_regex = '^:940:' # Start of relevant data
|
||||||
|
|||||||
Reference in New Issue
Block a user