예제 #1
0
def findMatchingTransfer(original_account, transaction,
                         accounts_transactions_list, accounts,
                         account_references):

    compare = transaction.copy()
    compare['amount'] = transaction['amount'] * -1
    for account_idx in range(len(accounts)):
        if accounts[account_idx]['ID'] != original_account:
            for t in accounts_transactions_list[account_idx]:
                if getYnabSyncId(t) == getYnabSyncId(compare):
                    reference = [
                        a for a in account_references
                        if a.id == accounts[account_idx]['account']
                    ]

                    d = {}
                    d['Name'] = accounts[account_idx]['Name']
                    d['account'] = accounts[account_idx]['account']
                    if len(reference) > 0 and hasattr(reference[0],
                                                      'transfer_payee_id'):
                        d['payee_id'] = reference[0].transfer_payee_id
                    else:
                        d['payee_id'] = None

                    return d
예제 #2
0
        try:
            payee_name = getPayee(transaction_item)
         # We raise ValueError in case there is Visa transaction that has no card details, skipping it so far
        except ValueError:
            pass
        
        logging.info("Transaction: %s,  amount: %s, typecode: %s, text: %s", getYnabTransactionDate(transaction_item), transaction_item['amount'], transaction_item['transactionTypeCode'], getMemo(transaction_item))

        ynab_transaction = ynab.TransactionDetail(
            date=getYnabTransactionDate(transaction_item), 
            amount=getIntAmountMilli(transaction_item), 
            cleared='uncleared', 
            approved=False, 
            account_id=account_map['account'],
            memo=getMemo(transaction_item),
            import_id=getYnabSyncId(transaction_item)
        )

        ynab_transaction.payee_name = payee_name

        if 'transactionFlagColor' in vars(api_settings) and api_settings.transactionFlagColor != None:
            ynab_transaction.flag_color = api_settings.transactionFlagColor

        if 'reservedFlagColor' in vars(api_settings) and api_settings.reservedFlagColor != None and (transaction_item.get('isReservation') == True or (transaction_item.get('otherAccountNumberSpecified') == False and transaction_item.get('source') != 'Archive')):
            ynab_transaction.flag_color = api_settings.reservedFlagColor


        # Change import_id if same amount on same day several times
        transaction_ref = ':'.join(ynab_transaction.import_id.split(':')[:3])
        if import_ids.count(transaction_ref) > 0:
            ynab_transaction.import_id=transaction_ref + ":" + str(import_ids.count(transaction_ref)+1)