Accountancy in Django

Okay, my in-line-authentication for Django is still somewhere on the shelf. But at the moment I'm looking for something to easily manage my financials in an online fashion. SQL Ledger doesn't fill my needs and most others aren't Open Source. So I'm trying my hand at writing my own program. Nothing very complicated with all kinds of features, but quite simple, bookkeeping. If I write something from there, it has to go somewhere else. Simple.

So I'm struggling with the model at the moment. This is what I have at this time:

from django.core import meta

class Currency(meta.Model): name = meta.CharField(maxlength=30) symbol = meta.CharField(maxlength=5)

class Account(meta.Model): name = meta.CharField(maxlength=50) number = meta.IntegerField() currency = meta.ForeignKey(Currency)

    def __repr__(self):
            return + " (" + self.number + ")"

class Transaction(meta.Model): date = meta.DateField() last_modified = meta.DateTimeField(auto_now=true) executor = meta.CharField(maxlength=50) total_amount = meta.FloatField(max_digits=25, decimal_places=3) currency = meta.ForeignKey(Currency) memo = meta.CharField(maxlength=255)

    def __repr__(self):
            return + " " + self.total_amount

class TransactionDebet(meta.Model): account = meta.ForeignKey(Account) transaction = meta.ForeignKey(Transaction) amount = meta.FloatField(max_digits=25, decimal_places=3) currency = meta.ForeignKey(Currency)

class TransactionCredit(meta.Model): account = meta.ForeignKey(Account) transaction = meta.ForeignKey(Transaction) amount = meta.FloatField(max_digits=25, decimal_places=3) currency = meta.ForeignKey(Currency)

The idea is simple. First of all, I want to include the possibility for several currencies. Even though I have absolutely no use for that part at the moment, I think it's wise to incorporate it already. The Account is a simple placeholder. It has a name and a number and nothing more. All other things are Transactions. Transactions should be the soul of the program, since it's the soul of bookkeeping, I think. (I'm no accountant, though.)

I've used GnuCash for some years now and I always liked the "split transaction" thingy. Not sure if other programs use that too, but I want it in my program. It makes it possible to say "I've recieved X from customer A, of which 19% will be tax and X-19% will be my actual income from this customer". More complicated things are possible, but this is what I'm going to use it for.

A Transaction can have several Debets or Credits. In the example above, I'll have 1 Debet and 2 Credits (or vice versa, I'm always confusing those). When the customer pays (Credit), it'll "cancel out" the Debet from the first Transaction. ... That sounds confusing. An example:

I bill customer A: They need to pay me €100 + €19 tax. So I make a Transaction with a Debet of €119 (the total amount I need to recieve from the customer) and two Credit Transactions, one with the amount of €100 (my actual income) and another of €19 (tax).

Customer A pays me the amount owed: A new Transaction in which I would recieve €119 from the Customer. It takes 1 Credit (I'm recieving the amount) and 1 Debet (I can subtract it from the amount this customer owes me).

If that sounds very confusing, go consult your accountant :)

Now I need to check if the sum of all Debets of a Transaction is equal to the sum of all Credits of a Transaction. If it isn't, the object isn't allowed to save(). I've seen the _pre_save() function, but at the moment, I can't find a way to actually stop the save() itself, preferably with a nice Error.

If you got any ideas, they're very welcome.


Comments powered by Disqus