コード例 #1
0
    def parse_record(self, line):
        if self.cur_record < 2:
            return None

        m = None
        parse_info = None

        if len(line) == 11:
            m = self.mt940_mappings
            parse_info = self.parse_transaction_info_mt940
        elif len(line) == 17:
            m = self.camt_mappings
            parse_info = self.parse_transaction_info_camt
        else:
            raise ValueError("invalid input line: '%s'" % line)

        if self.statement.account_id is None:
            self.statement.account_id = line[m["accid"]]

        sl = StatementLine()
        sl.date_avail = self.parse_datetime(line[m["valdate"]])
        if len(line[m["date"]]) > 0:
            sl.date = self.parse_datetime(line[m["date"]])
        else
            sl.date = sl.date_avail
        sl.amount = self.parse_float(line[m["amount"]])
        sl.trntype = self.parse_transaction_type(sl.amount,
                                                 line[m["btext"]])

        # remove leading or all) zeros
        line[m["toaccid"]] = line[m["toaccid"]].lstrip('0')

        if len(line[m["toaccid"]]) > 0 and len(line[m["tobankid"]]) > 0:
            # additional bank information is present
            splitted = self.parse_iban(line[m["toaccid"]])
            if splitted:
                sl.bank_account_to = BankAccount(**splitted)
            else:
                sl.bank_account_to = BankAccount(line[m["tobankid"]],
                                                 line[m["toaccid"]])

        if line[m["currency"]] != self.statement.currency:
            # different currency is used
            sl.currency = line[m["currency"]]

        # remove additional spaces in the payee
        sl.payee = re.sub(' +', ' ', line[m["payee"]])[:32]

        info = parse_info(line)
        # remove additional spaces in the memo
        sl.memo = "%s: %s" % (line[m["btext"]],
                              re.sub(' +', ' ', info["memo"].strip()))

        # we need to generate an ID because nothing is given
        sl.id = generate_stable_transaction_id(sl)
        return sl
コード例 #2
0
    def parse_record(self, line):
        if len(line) < 5:
            return None
        elif len(line) < 12:
            # possibly meta information about the account
            if "BLZ" in line[0]:
                self.statement.bank_id = line[1]
            elif "Konto" in line[0]:
                self.statement.account_id = line[1]

            return None

        if line[9] == "Anfangssaldo":
            self.statement.start_date = self.parse_datetime(line[0])
            self.statement.start_balance = self.parse_float(line[11])
            return None
        elif line[9] == "Endsaldo":
            self.statement.end_date = self.parse_datetime(line[0])
            self.statement.end_balance = self.parse_float(line[11])
            return None
        elif line[0] == "Buchungstag":
            # it's the table header
            return None

        sl = StatementLine()
        sl.date = self.parse_datetime(line[0])
        sl.date_avail = self.parse_datetime(line[1])

        # Note: amount has no sign. We need to guess it later...
        sl.amount = self.parse_float(line[11])

        info = self.parse_transaction_info(line)
        sl.amount *= info["sign"]
        sl.trntype = info["ttype"]

        if "iban" in info:
            # additional bank information if present
            sl.bank_account_to = BankAccount(**self.parse_iban(info["iban"]))

        if line[10] != self.statement.currency:
            # different currency is used
            sl.currency = line[10]

        # remove additional spaces in the payee
        sl.payee = re.sub(" +", " ", line[3].replace("\n", " ").strip())[:32]

        # remove additional spaces in the memo
        sl.memo = re.sub(" +", " ", info["memo"].strip())

        # we need to generate an ID because nothing is given
        sl.id = generate_stable_transaction_id(sl)
        return sl
コード例 #3
0
ファイル: test_ofx.py プロジェクト: genisysram/ofxstatement
    def test_ofxWriter(self) -> None:

        # Create sample statement:
        statement = Statement("BID", "ACCID", "LTL")
        statement.lines.append(
            StatementLine("1", datetime(2012, 2, 12), "Sample 1",
                          Decimal("15.4")))
        line = StatementLine("2", datetime(2012, 2, 12), "Sample 2",
                             Decimal("25.0"))
        line.payee = ""
        line.bank_account_to = BankAccount("SNORAS", "LT1232")
        line.bank_account_to.branch_id = "VNO"
        line.currency = Currency("USD")
        line.orig_currency = Currency("EUR", Decimal("3.4543"))
        statement.lines.append(line)

        # Create writer:
        writer = ofx.OfxWriter(statement)

        # Set the generation time so it is always predictable
        writer.genTime = datetime(2012, 3, 3, 0, 0, 0)

        assert prettyPrint(writer.toxml()) == SIMPLE_OFX