Ejemplo n.º 1
0
    def test_update_balance(self):
        # Make sure the Transaction model doesn't update the account
        Transaction.listen_off()

        # Delete the first transaction (827.59 of credit)
        t = Transaction.objects.select_related().get(pk=1)
        t.delete()
        a = t.account

        # The balance shouldn't have changed
        self.assertEqual(a.balance, Decimal('3701.55'))

        # Update the balance, only taking into account new transactions
        a.update_balance(all=False)

        # The balance still shouldn't have changed
        self.assertEqual(a.balance, Decimal('3701.55'))

        # Create a new transaction
        p = Payee.objects.get(pk=1)
        t = Transaction(account=a,
                        mobile=False,
                        payee=p,
                        amount=Decimal('300'),
                        date=datetime.date.today())
        t.save()

        # Update the balance once more
        a.update_balance(all=False)

        # The balance should now be +300 from the added transaction
        self.assertEqual(a.balance, Decimal('4001.55'))

        # Update the balance a final time
        a.update_balance(all=True)

        # The balance should now be completely up-to-date
        self.assertEqual(a.balance, Decimal('3173.96'))

        # Turn transaction listening back on for other tests
        Transaction.listen_on()
Ejemplo n.º 2
0
    def test_add_lots(self):
        """
        Simulates a synchronisation of a large amount of transactions
        """
        a = Account.objects.get(pk=1)
        p = Payee.objects.get(pk=1)

        total = a.balance
        orig = total.copy_abs()

        count = Transaction.objects.all().count()

        # Turn the signal listening off so we can update the account balance afterwards
        Transaction.listen_off()

        for i in range(1, 100):
            amount = Decimal('%.2f' % i)
            if i > 50:
                amount = amount.copy_negate()

            t = Transaction(account=a,
                            mobile=False,
                            payee=p,
                            amount=amount,
                            date=datetime.date.today())
            t.save()

            total += amount
            count += 1

        # Turn signal listening back on
        Transaction.listen_on()

        a = Account.objects.get(pk=1)

        # Make sure the balance hasn't been updated
        self.assertEqual(a.balance, orig)

        # Make sure the right number of transactions has been added
        self.assertEqual(Transaction.objects.all().count(), count)
Ejemplo n.º 3
0
    def test_update_balance(self):
        # Make sure the Transaction model doesn't update the account
        Transaction.listen_off()

        # Delete the first transaction (827.59 of credit)
        t = Transaction.objects.select_related().get(pk=1)
        t.delete()
        a = t.account

        # The balance shouldn't have changed
        self.assertEqual(a.balance, Decimal("3701.55"))

        # Update the balance, only taking into account new transactions
        a.update_balance(all=False)

        # The balance still shouldn't have changed
        self.assertEqual(a.balance, Decimal("3701.55"))

        # Create a new transaction
        p = Payee.objects.get(pk=1)
        t = Transaction(account=a, mobile=False, payee=p, amount=Decimal("300"), date=datetime.date.today())
        t.save()

        # Update the balance once more
        a.update_balance(all=False)

        # The balance should now be +300 from the added transaction
        self.assertEqual(a.balance, Decimal("4001.55"))

        # Update the balance a final time
        a.update_balance(all=True)

        # The balance should now be completely up-to-date
        self.assertEqual(a.balance, Decimal("3173.96"))

        # Turn transaction listening back on for other tests
        Transaction.listen_on()
Ejemplo n.º 4
0
    def test_add_lots(self):
        """
        Simulates a synchronisation of a large amount of transactions
        """
        a = Account.objects.get(pk=1)
        p = Payee.objects.get(pk=1)

        total = a.balance
        orig = total.copy_abs()

        count = Transaction.objects.all().count()

        # Turn the signal listening off so we can update the account balance afterwards
        Transaction.listen_off()

        for i in range(1, 100):
            amount = Decimal("%.2f" % i)
            if i > 50:
                amount = amount.copy_negate()

            t = Transaction(account=a, mobile=False, payee=p, amount=amount, date=datetime.date.today())
            t.save()

            total += amount
            count += 1

        # Turn signal listening back on
        Transaction.listen_on()

        a = Account.objects.get(pk=1)

        # Make sure the balance hasn't been updated
        self.assertEqual(a.balance, orig)

        # Make sure the right number of transactions has been added
        self.assertEqual(Transaction.objects.all().count(), count)
Ejemplo n.º 5
0
         # Otherwise if credit is anything but 0 assume it's a positive value
         if transactions[i]['credit'] == 0:
             t.amount = '%s' % (-abs(float(t.amount)))
         else:
             t.amount = '%s' % abs(float(t.amount))
     
     # Try to get the date from the POSTed values
     try:
         t.date = datetime.date.fromtimestamp(float(transactions[i]['date']))
     except KeyError, ValueError:
         # KeyError means we don't have one in the POST data
         # ValueError means we couldn't decode it
         t.date = datetime.date.today()
         
     # If we have a comment, decode it
     if 'comment' in transactions[i].keys():
         comment = transactions[i]['comment']
         if type(comment) is str:
             comment = comment.decode('utf-8')
         t.comment = comment
         
     t.save()
 
 # Turn signal listening back on
 Transaction.listen_on()
 
 # Now we can update the balance of all the accounts we've dealt with
 for a in accounts:
     accounts[a].update_balance()
 
 return HttpResponse(json.dumps({'errors': errors}), content_type='application/javascript; charset=utf-8')
Ejemplo n.º 6
0
            else:
                t.amount = '%s' % abs(float(t.amount))

        # Try to get the date from the POSTed values
        try:
            t.date = datetime.date.fromtimestamp(float(
                transactions[i]['date']))
        except KeyError, ValueError:
            # KeyError means we don't have one in the POST data
            # ValueError means we couldn't decode it
            t.date = datetime.date.today()

        # If we have a comment, decode it
        if 'comment' in transactions[i].keys():
            comment = transactions[i]['comment']
            if type(comment) is str:
                comment = comment.decode('utf-8')
            t.comment = comment

        t.save()

    # Turn signal listening back on
    Transaction.listen_on()

    # Now we can update the balance of all the accounts we've dealt with
    for a in accounts:
        accounts[a].update_balance()

    return HttpResponse(json.dumps({'errors': errors}),
                        content_type='application/javascript; charset=utf-8')