def test_simple(self):
     res = OFXTransaction.params_from_ofxparser_transaction(
         self.trans, self.acct_id, self.stmt)
     assert res == {
         'account_id': self.acct_id,
         'statement': self.stmt,
         'memo': 'TMemo',
         'name': 'PayeeName',
         'amount': 123.45,
         'trans_type': 'TType',
         'date_posted': datetime(2017, 3, 10, 14, 15, 16, tzinfo=UTC),
         'fitid': 'ABC123',
         'sic': None,
         'mcc': ''
     }
Ejemplo n.º 2
0
    def _update_bank_or_credit(self, acct, ofx, stmt):
        """
        Update a single OFX file for this Bank or Credit account.

        :param acct: the Account this statement is for
        :type acct: biweeklybudget.models.account.Account
        :param ofx: Ofx instance for parsed file
        :type ofx: ``ofxparse.ofxparse.Ofx``
        :param stmt: the OFXStatement for this statement
        :type stmt: biweeklybudget.models.ofx_statement.OFXStatement
        :returns: the OFXStatement object
        :rtype: biweeklybudget.models.ofx_statement.OFXStatement
        """
        # Note that as of 0.16, OfxParser returns tz-naive UTC datetimes
        logger.debug('Updating Bank/Credit account')
        if hasattr(ofx.account.statement, 'available_balance'):
            stmt.avail_bal = ofx.account.statement.available_balance
        if hasattr(ofx.account.statement, 'available_balance_date'):
            stmt.avail_bal_as_of = \
                ofx.account.statement.available_balance_date.replace(tzinfo=UTC)
        stmt.ledger_bal = ofx.account.statement.balance
        stmt.ledger_bal_as_of = \
            ofx.account.statement.balance_date.replace(tzinfo=UTC)
        db_session.add(stmt)
        acct.set_balance(
            overall_date=stmt.as_of,
            ledger=stmt.ledger_bal,
            ledger_date=stmt.ledger_bal_as_of,
            avail=stmt.avail_bal,
            avail_date=stmt.avail_bal_as_of
        )
        for txn in ofx.account.statement.transactions:
            try:
                kwargs = OFXTransaction.params_from_ofxparser_transaction(
                    txn, acct.id, stmt, cat_memo=acct.ofx_cat_memo_to_name
                )
            except RuntimeError as ex:
                logger.error(ex)
                continue
            upsert_record(
                OFXTransaction,
                ['account_id', 'fitid'],
                **kwargs
            )
        return stmt
 def test_extra_attrs(self):
     self.trans.mcc = 'TMCC'
     self.trans.sic = 456
     self.trans.checknum = 789
     res = OFXTransaction.params_from_ofxparser_transaction(
         self.trans, self.acct_id, self.stmt)
     assert res == {
         'account_id': self.acct_id,
         'statement': self.stmt,
         'memo': 'TMemo',
         'name': 'PayeeName',
         'amount': 123.45,
         'trans_type': 'TType',
         'date_posted': datetime(2017, 3, 10, 14, 15, 16, tzinfo=UTC),
         'fitid': 'ABC123',
         'sic': 456,
         'mcc': 'TMCC',
         'checknum': 789
     }