コード例 #1
0
ファイル: import_qif_test.py プロジェクト: Spudwars/finance
 def test_parse_normarl_transactions(self):
     ts = parse_qif(NORMAL_TRANSACTIONS.splitlines(), dayfirst=False)    
     assert len(ts) == 3
     
     assert ts == [
         {'amount': -1000.0,
          'amount_in_split': [-253.63999999999999, -746.36000000000001],
          'category': '[linda]',
          'category_in_split': ['[linda]', 'Mort Int'],
          'date': datetime(1994, 6, 1, 0, 0),
          'import_string': 'D6/ 1/94\nT-1,000.00\nN1005\nPBank Of Mortgage\nL[linda]\nS[linda]\n$-253.64\nSMort Int\n$-746.36\n^\n',
          'number': '1005',
          'payee': 'Bank Of Mortgage'},
         {'amount': 75.0,
          'date': datetime(1994, 6, 2, 0, 0),
          'import_string': 'D6/ 2/94\nT75.00\nPDeposit\n^\n',
          'payee': 'Deposit'},
         {'address': '',
          'amount': -10.0,
          'category': 'Entertain',
          'date': datetime(1994, 6, 3, 0, 0),
          'import_string': 'D6/ 3/94\nT-10.00\nPJoBob Biggs\nMJ.B. gets bucks\nLEntertain\nA1010 Rodeo Dr.\nAWaco, Tx\nA80505\nA\nA\nA\n^\n',
          'memo': 'J.B. gets bucks',
          'payee': 'JoBob Biggs'}
     ]
コード例 #2
0
ファイル: views.py プロジェクト: Spudwars/finance
def import_qif(filename, account):
    """
    """
    with open(filename, 'rb') as qif_file:
        transactions = parse_qif(qif_file)
    logging.info("%d QIF transactions found in file %s", len(transactions), filename)
    for t in transactions:
        try:
            trans_type, payee = match_transaction_type(t['payee'])
        except ValueError:
            logging.warning("Transaction type cannot be determined: %s", t['payee'])
            trans_type = None
            payee = t['payee']

        # create and save Transactions in DB            
        new_transaction = Transaction(
            account = account,
            name = payee, #TODO: populate or remove as we don't need a name?!
            date = t['date'],
            transaction_type = trans_type,
            payee = payee,
            ##paid_on = paid_on_dt,
            import_string = t['import_string'],
        )  
        new_transaction.save()
        
        if t.get('amount_in_split'):
            part_list = []
            for n, amount in t['amount_in_split']:
                # create and save Transactions in DB
                if t.get('category_in_split'):
                    # assumed category_in_split has same number of items as amount
                    split_category = _get_category(t['category_in_split'][n])
                else:
                    split_category = match_category(payee)
                    
                t_part = TransactionPart(
                    transaction = new_transaction,
                    amount = '%.2f' % amount,
                    category = split_category,
                    description  = '', #TODO: iterate over t['memo'] field if available
                )
                t_part.save() #TODO: Required again after?
                part_list.append(t_part)
            logging.debug("Imported %s - %s", new_transaction, part_list)
                    
        else:
            # create a single transactionamount
            if t.get('category'):
                # Category from QIF takes priority if available
                category = _get_category(category_name)
            else:
                category = match_category(payee)
            t_part = TransactionPart(
                transaction = new_transaction,
                amount = '%.2f' % t['amount'],
                description = t.get('memo', ''),
                category = category,
            )
            t_part.save() #TODO: Required again after?
            logging.debug("Imported %s - %s", new_transaction, t_part)
    return len(transactions)
コード例 #3
0
ファイル: import_qif_test.py プロジェクト: Spudwars/finance
 def test_parse_sample(self):
     ts = parse_qif(SAMPLE.splitlines())  
     assert len(ts) == 3