示例#1
0
def import_transaction(transaction):
    if MONZO_ACC != transaction['account_id']:
        return None

    amount = transaction['amount']
    if amount >= 0:
        return None

    expense = Expense()
    # @TODO need to work out the user-id here
    expense.user_id = 1
    expense.type = transaction['category']

    created = transaction['created']
    try:
        expense.date = datetime.strptime(created, '%Y-%m-%dT%H:%M:%S.%fZ')
    except ValueError:
        logger.error('Unrecognised date format: %s' % created)

    expense.value = abs(transaction['amount'] / 100.0)
    expense.monzo_id = transaction['id']
    expense.reference = transaction['description']
    if 'merchant' in transaction and transaction['merchant']:
        merchant = transaction['merchant']
        notes = merchant['name']
        if 'address' in merchant:
            notes += ', ' + merchant['address'].get('short_formatted', '')
        expense.notes = notes

    return expense
示例#2
0
 def import_transaction(self, transaction):
     amount = transaction['amount']
     if amount >= 0:
         return
     expense = Expense()
     expense.user = self.user
     expense.type = transaction['category']
     expense.date = datetime.strptime(
         transaction['created'],
         '%Y-%m-%dT%H:%M:%S.%fZ'
     )
     expense.value = transaction['amount'] / 100.0
     expense.monzo_id = transaction['id']
     expense.reference = transaction['description']
     if 'merchant' in transaction and transaction['merchant']:
         merchant = transaction['merchant']
         notes = merchant['name']
         if 'address' in merchant:
             notes += ', ' + merchant['address']['short_formatted']
         expense.notes = notes
     expense.save()