Exemple #1
0
    def parse_record(self, line):
        """Parse given transaction line and return StatementLine object
        """
        transaction = statement.StatementLine()

        transaction.date_user = datetime.strptime(line['operation_date'],
                                                  operation_date_format)
        if line['status'] != statuses['PROCESSING']:
            if self.user_date:
                transaction.date = transaction.date_user
            else:
                transaction.date = self.parse_datetime(line['processing_date'])
        transaction.memo = line['reason']
        transaction.amount = self._parse_decimal(line['account_amount'])
        transaction.payee = self.parse_payee(line['reason'])
        transaction.trntype = self.parse_type(transaction.amount)

        # as csv file does not contain explicit id of transaction, generating artificial one
        # using operation date as main date in all cases
        transaction.id = statement.generate_transaction_id(
            statement.StatementLine(date=transaction.date_user,
                                    memo=transaction.memo,
                                    amount=transaction.amount))

        return transaction
    def parse_record(self, line):
        transaction = statement.StatementLine()

        transaction.date = datetime.strptime(
            line[('op_time' if line['op_time'] else 'tr_time')],
            av_time_format)

        transaction.amount = (float(line['debit']) if line['debit'] else 0) - (
            float(line['credit']) if line['credit'] else 0)

        transaction.trntype = parse_type(line['type'], transaction.amount)

        transaction.memo = line['description'] if line[
            'description'] else line['type']

        if line['MCC']:
            transaction.memo = "%s, %s" % (transaction.memo, line['MCC'])

        if line['card']:
            transaction.memo = "%s, %s" % (transaction.memo, line['card'])

        # as csv file does not contain explicit id of transaction, generating artificial one
        transaction.id = statement.generate_transaction_id(transaction)

        if transaction.trntype:
            return transaction
        else:
            return None
    def parse_record(self, line):
        transaction = statement.StatementLine()

        if not self.statement.account_id:
            self.statement.account_id = line['acc']

        if not self.statement.currency:
            self.statement.currency = line['currency']

        if not line['currency'] == self.statement.currency:
            print(
                "Transaction %s currency '%s' differ from account currency '%s'."
                % (line['op_time'], line['currency'], self.statement.currency))
            return None

        transaction.date = self.parse_datetime(line['op_time'])
        date_user = self.try_find_user_date(line['description'])

        if self.user_date and date_user:
            transaction.date = self.parse_datetime(date_user)

        transaction.amount = self.get_amount(line['income'], line['withdraw'])

        transaction.trntype = parse_type(line['description'],
                                         transaction.amount)
        transaction.refnum = line['refnum']

        transaction.memo = line['description']

        if transaction.trntype:
            return transaction
        else:
            return None
Exemple #4
0
    def parse_record(self, line):
        transaction = statement.StatementLine()

        if not line['status'] == 'OK':
            print("Notice: Skipping line %d: Transaction time %s status is %s." % (
                self.cur_record, line['op_time'], line['status']))
            return None

        if not self.statement.currency:
            self.statement.currency = line['currency']

        if not line['currency'] == self.statement.currency:
            print("Transaction %s currency '%s' differ from account currency '%s'." % (
                line['op_time'], line['currency'], self.statement.currency))
            return None

        transaction.date = datetime.strptime(line['op_time'], t_time_format)

        transaction.amount = Decimal(line['amount'].replace(',', '.'))

        transaction.trntype = parse_type(line['description'], transaction.amount)

        transaction.memo = "%s: %s" % (line['category'], line['description'])

        self._append_to_memo(transaction, line, 'MCC')
        self._append_to_memo(transaction, line, 'card')

        # as csv file does not contain explicit id of transaction, generating artificial one
        transaction.id = statement.generate_transaction_id(transaction)

        if transaction.trntype:
            return transaction
        else:
            return None
    def parse_record(self, line):
        transaction = statement.StatementLine()

        transaction.date = datetime.strptime(
            line[('op_time' if line['op_time'] else 'tr_time')],
            av_time_format)

        transaction.amount = (float(line['debit']) if line['debit'] else 0) - (
            float(line['credit']) if line['credit'] else 0)

        transaction.trntype = parse_type(line['type'], transaction.amount)

        transaction.memo = line['description'] if line[
            'description'] else line['type']

        if line['MCC']:
            transaction.memo = "%s, %s" % (transaction.memo, line['MCC'])

        if line['card']:
            transaction.memo = "%s, %s" % (transaction.memo, line['card'])

        if transaction.trntype:
            return transaction
        else:
            return None
    def parse_record(self, line):
        transaction = statement.StatementLine()

        if not line['status'] == 'OK':
            print("Notice: Skipping line %d: Transaction time %s status is %s." % (
            self.cur_record, line['op_time'], line['status']))
            return None

        if not self.statement.currency:
            self.statement.currency = line['currency']

        if not line['currency'] == self.statement.currency:
            print("Transaction %s currency '%s' differ from account currency '%s'." % (
            line['op_time'], line['currency'], self.statement.currency))
            return None

        transaction.date = datetime.strptime(line['op_time'], t_time_format)

        transaction.amount = float(line['amount'].replace(',', '.'))

        transaction.trntype = parse_type(line['description'], transaction.amount)

        transaction.memo = "%s: %s" % (line['category'], line['description'])

        if line['MCC']:
            transaction.memo = "%s, %s" % (transaction.memo, line['MCC'])

        if line['card']:
            transaction.memo = "%s, %s" % (transaction.memo, line['card'])

        if transaction.trntype:
            return transaction
        else:
            return None
    def test_generate_unique_transaction_id(self) -> None:
        # GIVEN
        stl = statement.StatementLine("one", datetime(2020, 3, 25))
        txnids: Set[str] = set()

        # WHEN
        tid1 = statement.generate_unique_transaction_id(stl, txnids)
        tid2 = statement.generate_unique_transaction_id(stl, txnids)

        self.assertNotEqual(tid1, tid2)

        self.assertTrue(tid2.endswith("-1"))
        self.assertEqual(len(txnids), 2)
Exemple #8
0
    def test_generate_transaction_id_idempotent(self):
        # GIVEN
        stl = statement.StatementLine(
            "one", date(2020, 3, 25), memo='123', amount=Decimal("12.43"))
        tid1 = statement.generate_transaction_id(stl)

        # WHEN
        # Subsequent calls with the same data generates exactly the same
        # transaction id
        tid2 = statement.generate_transaction_id(stl)

        # THEN
        self.assertEqual(tid1, tid2)
Exemple #9
0
    def test_generate_transaction_id_identifying(self):
        # GIVEN
        stl = statement.StatementLine(
            "one", date(2020, 3, 25), memo='123', amount=Decimal("12.43"))
        tid1 = statement.generate_transaction_id(stl)

        # WHEN
        # Different data generates different transaction id
        stl.amount = Decimal("1.01")
        tid2 = statement.generate_transaction_id(stl)

        # THEN
        self.assertNotEqual(tid1, tid2)
    def extractTransaction(self, match):
        if self.transaction:
            self.transaction.memo = " ".join(self.transaction.memo.split())
            self.statement.lines.append(self.transaction)

        self.transaction = statement.StatementLine()

        self.account_fl_len = len(match.group(1))

        self.transaction.date = self.parseDate(match.group(3))
        self.transaction.memo = match.group(4)
        self.transaction.amount = float(
            match.group(5)) * (1 if match.group(6) else -1)
        self.transaction.trntype = 'DEBIT' if match.group(6) else 'CREDIT'
        if match.group(1).strip():
            self.account_id += match.group(1)
Exemple #11
0
    def parse_record(self, row):
        """Parse given transaction line and return StatementLine object
        """
        stmt_line = statement.StatementLine()

        if self.cur_tpl == 'savings' or self.cur_tpl == 'savings_legacy':
            col_shift = 1 if self.cur_tpl == 'savings_legacy' else 0
            if row[1+col_shift]:
                income = row[1+col_shift]
                outcome = 0
                stmt_line.trntype = "CREDIT"
            elif row[2+col_shift]:
                outcome = row[2+col_shift]
                income = 0
                stmt_line.trntype = "DEBIT"

            memo_short = row[3+col_shift]
            if memo_short.startswith(self.tpl['savings']['xfer_str']):
                stmt_line.trntype = "XFER"
            elif memo_short.startswith(self.tpl['savings']['cash_str']):
                stmt_line.trntype = "CASH"

            stmt_line.memo = row[4+col_shift]
            if self.extra_field and row[6] != '':
                stmt_line.memo = stmt_line.memo + ' - ' + row[6]

            stmt_line.amount = self.calc_amount(income, outcome)

        elif self.cur_tpl == 'cards':
            if row[3] == 'P':
                stmt_line.trntype = "CASH"

            if row[ self.tpl['cards']['amount_field'] ] < 0:
                stmt_line.trntype = "DEBIT"
            else:
                stmt_line.trntype = "CREDIT"

            stmt_line.memo = row[2]
            stmt_line.amount = row[ self.tpl['cards']['amount_field'] ]

        if self.memo2payee:
            stmt_line.payee = stmt_line.memo

        stmt_line.date = datetime.strptime(row[0], self.date_format)
        stmt_line.id = statement.generate_transaction_id(stmt_line)

        return stmt_line
Exemple #12
0
    def parse_record(self, line):
        """Parse given transaction line and return StatementLine object
        """
        transaction = statement.StatementLine()

        transaction.date_user = datetime.strptime(line['operation_date'],
                                                  operation_date_format)
        if line['status'] != statuses['PROCESSING']:
            if self.user_date:
                transaction.date = transaction.date_user
            else:
                transaction.date = self.parse_datetime(line['processing_date'])
        transaction.memo = line['reason']
        transaction.amount = self.parse_decimal(line['account_amount'])
        transaction.payee = self.parse_payee(line['reason'])
        transaction.trntype = self.parse_type(transaction.amount)

        return transaction
    def parse_record(self, line):
        transaction = statement.StatementLine()

        if not self.statement.account_id:
            self.statement.account_id = '{} {}'.format(line['card_type'],
                                                       line['card_num'])

        transaction.date = datetime.strptime(line['date'], SD_TIME_FORMAT)
        transaction.date_user = datetime.strptime(line['date_user'],
                                                  SD_TIME_FORMAT)

        transaction.amount = float(line['amount'].replace(',', '.'))

        transaction.trntype = 'DEBIT' if transaction.amount > 0 else 'CREDIT'

        transaction.memo = ', '.join(line[f]
                                     for f in ('description', 'op_city',
                                               'op_country', 'op_type')
                                     if line[f])

        return transaction
Exemple #14
0
    def parse_record(self, line):
        transaction = statement.StatementLine()

        if not self.statement.account_id:
            self.statement.account_id = '{} {}'.format(line['card_type'],
                                                       line['card_num'])

        transaction.date = datetime.strptime(line['date'], SD_TIME_FORMAT)
        transaction.date_user = datetime.strptime(line['date_user'],
                                                  SD_TIME_FORMAT)

        transaction.amount = Decimal(line['amount'].replace(',', '.'))

        transaction.trntype = 'DEBIT' if transaction.amount > 0 else 'CREDIT'

        transaction.memo = ', '.join(line[f]
                                     for f in ('description', 'op_city',
                                               'op_country', 'op_type')
                                     if line[f])

        # as csv file does not contain explicit id of transaction, generating artificial one
        transaction.id = statement.generate_transaction_id(transaction)

        return transaction