Browse Source

Add support for Raiffeisen Bank

Alois Mahdal 5 years ago
parent
commit
823f186728
1 changed files with 100 additions and 0 deletions
  1. 100
    0
      gcconv.py

+ 100
- 0
gcconv.py View File

@@ -262,7 +262,107 @@ class FioTransactionParser(BaseTransactionParser):
262 262
         return self.state
263 263
 
264 264
 
265
+class RaifTransaction(BaseTransaction):
266
+
267
+    # (a) Transaction Date
268
+    # (b) Booking Date
269
+    # (c) Account number
270
+    # (d) Account Name
271
+    # (e) Transaction Category
272
+    # (f) Accocunt Number
273
+    # (g) Name of Account
274
+    # (h) Transaction type
275
+    # (i) Message
276
+    # (j) Note
277
+    # (k) VS
278
+    # (l) KS
279
+    # (m) SS
280
+    # (n) Booked amount
281
+    # (o) Account Currency
282
+    # (p) Original Amount and Currency
283
+    # (q) Original Amount and Currency
284
+    # (r) Fee
285
+    # (s) Transaction ID
286
+
287
+    def __init__(self, line):
288
+        self._fields = [self._cleanup_field(f) for f in line.split(";")]
289
+        self.date = self._convert_date(self._fields[0])
290
+        amount = self._parse_currency(self._fields[13])
291
+        if amount >= 0:
292
+            self.amountd = amount
293
+            self.amountw = 0
294
+        else:
295
+            self.amountd = 0
296
+            self.amountw = -amount
297
+        self.currency = self._fields[14]
298
+        assert self.currency == 'CZK'
299
+
300
+    def _cleanup_field(self, field):
301
+        x = ' '.join(_unquote(field).strip().split())
302
+        return '' if x == '-' else x
303
+
304
+    def _description(self):
305
+        (
306
+            transaction_date,
307
+            booking_date,
308
+            account_number,
309
+            account_name,
310
+            transaction_category,
311
+            accocunt_number,
312
+            name_of_account,
313
+            transaction_type,
314
+            message,
315
+            note,
316
+            vs,
317
+            ks,
318
+            ss,
319
+            booked_amount,
320
+            account_currency,
321
+            original_amount_and_currency,
322
+            original_amount_and_currency,
323
+            fee,
324
+            transaction_id,
325
+            ) = self._fields
326
+        out = []
327
+        if message:
328
+            out.append(message)
329
+        if note and note != message:
330
+            out.append(note)
331
+        return " / ".join(out)
332
+
333
+    def _convert_date(self, text):
334
+        day, month, year = text.split('.')
335
+        return '-'.join([year, month, day])
336
+
337
+    def _parse_currency(self, text):
338
+        return float(text.replace(',', '.').replace(' ', ''))
339
+
340
+    def to_gc(self):
341
+        """Convert to GCTransaction"""
342
+        return GCTransaction(
343
+            date=self.date,
344
+            deposit=self.amountd,
345
+            withdrawal=self.amountw,
346
+            description=self._description()
347
+        )
348
+
349
+
350
+class RaifTransactionParser(BaseTransactionParser):
351
+
352
+    def parse_line(self, line):
353
+        return RaifTransaction(line)
354
+
355
+    def advance(self, line, lineno=None):
356
+        """Choose parser state according to current line and line no."""
357
+        if self.state.nxt:
358
+            return ParserState(ths=True, nxt=False)
359
+        if self.is_closed() and line.startswith(u'Transaction Date;Booking'):
360
+            return ParserState(ths=False, nxt=True)
361
+        return self.state
362
+
363
+
265 364
 _parsers = {
266 365
     'CzMbank': MbankTransactionParser,
267 366
     'CzFio': FioTransactionParser,
367
+    'CzRaif': RaifTransactionParser,
268 368
 }