Created
August 7, 2012 13:36
-
-
Save codeinthehole/3285411 to your computer and use it in GitHub Desktop.
Models for double-book-keeping accounting for managed budgets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
class Ledger(models.Model): | |
# There can only be one 'Labour' and 'Shop' ledger but lots of 'Budget' | |
# ledgers. | |
LABOUR, BUDGET, SHOP = 'Labour', 'Budget', 'Shop' | |
LEDGER_CHOICES = ( | |
(LABOUR, LABOUR), | |
(BUDGET, BUDGET), | |
(SHOP, SHOP), | |
) | |
type = models.CharField(max_length=128, choices=LEDGER_CHOICES) | |
name = models.CharField(max_length=128, unique=True) | |
class Transaction(models.Model): | |
# Every transfer of money should create two rows in this table. | |
# (a) the debit from the source ledger | |
# (b) the credit to the destination ledger | |
ledger = models.CharField(max_length=128) | |
debit_amount = models.DecimalField(decimal_places=2, max_digits=12) | |
credit_amount = models.DecimalField(decimal_places=2, max_digits=12) | |
date_created = models.DateTimeField(auto_now_add=True) | |
class Budget(models.Model): | |
name = models.CharField(max_length=128, unique=True) | |
ledger = models.OneToOneField(Ledger, related_name='transactions') | |
# This is entered at checkout to pay using budget | |
code = models.CharField(max_length=128, unique=True) | |
# Audit information | |
initial_balance = models.DecimalField(decimal_places=2, max_digits=12) | |
current_balance = models.DecimalField(decimal_places=2, max_digits=12) | |
expiry_date = models.DateField() | |
users = models.ManyToManyField('auth.User') | |
products = models.ManyToManyField('catalogue.Product') | |
date_created = models.DateTimeField(auto_now_add=True) | |
date_last_transation = models.DateTimeField(null=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment