77
77
# Normalize basic account numbers
78
78
self.remote_account = self.remote_account.replace('.', '').zfill(10)
79
79
self.local_account = self.local_account.replace('.', '').zfill(10)
81
82
class transaction(models.mem_bank_transaction):
115
116
# global expression for matching storno references
116
117
ref_expr = re.compile('REF[\*:]([0-9A-Z-z_-]+)')
118
# match references for Acceptgiro's through Internet banking
119
kn_expr = re.compile('KN: ([^ ]+)')
118
121
def __init__(self, line, *args, **kwargs):
149
152
self.reference = res.group(1)
150
153
self.storno_retry = True
151
154
self.remote_owner = False
155
if self.transfer_type == 'GT':
156
res = self.kn_expr.search(self.message)
158
self.reference = res.group(1)
159
if self.transfer_type == 'AC':
160
self.parse_acceptgiro()
161
if self.message and not self.reference:
162
self.reference = self.message
164
def parse_acceptgiro(self):
166
Entries of type 'Acceptgiro' can contain the reference
167
in the 'name' column, as well as full address information
168
in the 'message' column'
175
if self.remote_owner.startswith('KN: '):
176
self.reference = self.remote_owner[4:]
177
self.remote_owner = ''
178
if 'KN: ' in self.message:
179
index = self.message.index('KN: ')
180
before = self.message[:index]
181
self.message = self.message[index:]
183
"^\s*(KN:\s*(?P<kn>[^\s]+))?(\s*)"
184
"(?P<navr>NAVR:\s*[^\s]+)?(\s*)(?P<after>.*?)$")
185
msg_match = re.match(expression, self.message)
186
after = msg_match.group('after')
187
kn = msg_match.group('kn')
188
navr = msg_match.group('navr')
190
self.reference = kn[4:]
191
self.message = 'Acceptgiro %s' % (navr or '')
193
parts = [after[i:i+33] for i in range(0, len(after), 33)]
194
if parts and not self.remote_owner:
195
self.remote_owner = parts.pop(0).strip()
197
self.remote_owner_address = [parts.pop(0).strip()]
199
zip_city = parts.pop(0).strip()
200
zip_match = re.match(
201
"^(?P<zipcode>[^ ]{6})\s+(?P<city>.*?)$", zip_city)
203
self.remote_owner_postalcode = zip_match.group('zipcode')
204
self.remote_owner_city = zip_match.group('city')
205
if before and not self.remote_owner_city:
206
self.remote_owner_city = before.strip()
153
208
def is_valid(self):
154
209
if not self.error_message: