public
Description: Django-beancounter is a simple app I built to track my income and expenses.
Homepage: http://github.com/lincolnloop/django-beancounter
Clone URL: git://github.com/lincolnloop/django-beancounter.git
lincolnloop (author)
Sun Jan 04 17:41:51 -0800 2009
commit  3431c1032d66ef29e874b66482b590d1a25a1b48
tree    7ca2a2ff170f78fc07b7406fe075861388dd7505
parent  d19870c8fdeab21e921453632d5169b8445728d3
100644 160 lines (130 sloc) 6.025 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
import datetime
 
from django.db import models
from django.contrib.localflavor.us.models import PhoneNumberField
from tagging.fields import TagField
 
TYPE_CHOICES = (
    ('INC', 'Income'),
    ('EXP', 'Expense'),
    ('COGS', 'Cost of Goods Sold'),
)
class Category(models.Model):
    type = models.CharField(max_length=4,choices=TYPE_CHOICES)
    name = models.CharField(max_length=50)
    income = models.ForeignKey('self', null=True, blank=True, limit_choices_to = {'type__exact':'INC'}, help_text='Use this to enable tracking your costs of goods vs. income')
 
    def __str__(self):
        return "%s: %s" % (self.type,self.name)
    class Meta:
        verbose_name_plural = 'Categories'
        ordering = ['type','name']
    
    class Admin:
        fields = (
            (None, {
                'fields': ('type','name')
            }),
            ('Associate Costs of Goods Sold to an Income Category', {
                'classes': 'collapse',
                'fields' : ('income',)
            }),
        )
    
class BankAccount(models.Model):
    type = models.CharField(max_length=50,help_text='Checking, Savings, Credit, etc.')
    name = models.CharField(max_length=50)
    initial_balance = models.DecimalField(max_digits=10, decimal_places=2, null=True,blank=True)
    track_balance = models.BooleanField(help_text='Generate reports of the balance of this account over time.')
 
    def __str__(self):
        return "%s (%s)" % (self.name,self.type)
    class Admin:
        list_display = ('name','type')
        ordering = ['-track_balance','name','type']
        
class AccountTransfer(models.Model):
    date = models.DateField()
    from_account = models.ForeignKey(BankAccount,related_name='transferred_from')
    to_account = models.ForeignKey(BankAccount,related_name='transferred_to')
    amount = models.DecimalField(max_digits=8, decimal_places=2)
    memo = models.CharField(max_length=100,null=True,blank=True)
    def __str__(self):
        return "$%.2f from %s to %s" % (self.amount,self.from_account,self.to_account)
        
    class Admin:
        list_display = ('date','amount','from_account','to_account')
        list_filter = ('to_account','from_account')
        date_hierarchy = 'date'
        
        
class Person(models.Model):
    name = models.CharField(max_length=100)
    contact = models.CharField(max_length=100,null=True,blank=True)
    phone = PhoneNumberField(null=True,blank=True)
    website = models.URLField(null=True,blank=True)
    email = models.EmailField(null=True,blank=True)
    notes = models.CharField(max_length=100,null=True,blank=True)
    
    def __unicode__(self):
        return self.name
    
    class Meta:
        verbose_name_plural = 'People'
        ordering = ['name']
        
        
class Employee(Person):
    PAYMENT_CHOICES = (
        ('paypal', 'PayPal'),
        ('check', 'Mail Check'),
        ('wire', 'Wire Transfer'),
        ('elance', 'Elance'),
        ('other', 'Other'),
    )
    gmt_offset = models.DecimalField(max_digits=3, decimal_places=1)
    skills = TagField()
    payment_preference = models.CharField(blank=True, max_length=100, choices=PAYMENT_CHOICES)
    payment_notes = models.TextField(blank=True)
    contract = models.DateField(blank=True, null=True, help_text="Date contractor contract was signed and received.")
    hourly_rate = models.DecimalField(max_digits=5, decimal_places=2, blank=True, null=True, help_text="If rate varies, enter average and note below.")
    currency = models.CharField(default="USD", max_length=3)
    rate_notes = models.TextField(blank=True, help_text="Additional notes regarding contractor rates.")
 
 
    def timezone(self):
        if self.gmt_offset == int(self.gmt_offset):
            gmt_offset = int(self.gmt_offset)
        else:
            gmt_offset = self.gmt_offset
        if gmt_offset > 0:
            gmt_offset = '+%s' % gmt_offset
        return 'GMT%s' % gmt_offset
 
    def under_contract(self):
        if self.contract:
            return True
        return False
    under_contract.boolean = True
 
    def rate(self):
        return "%s %s" % (self.hourly_rate, self.currency)
 
class Project(models.Model):
    name = models.CharField(max_length=100)
    employees = models.ManyToManyField(Employee)
    start_date = models.DateField()
    bid = models.DecimalField(max_digits=8, decimal_places=2)
    active = models.BooleanField(default=True)
 
    def __unicode__(self):
        return self.name
        
        
class ProjectTime(models.Model):
    """
Hours spent by an employee on a project
"""
    
    employee = models.ForeignKey(Employee)
    project = models.ForeignKey(Project)
    start_date = models.DateField(default=datetime.date.today())
    end_date = models.DateField(default=datetime.date.today())
    hours = models.DecimalField(max_digits=6, decimal_places=3)
    cost = models.DecimalField(max_digits=9, decimal_places=2, blank=True, null=True, help_text="Leave blank to automatically calculate")
    cost_converted = models.DecimalField(max_digits=9, decimal_places=2, blank=True, null=True, help_text="Cost converted to local currency")
 
    def __unicode__(self):
        return "%s on %s (%s-%s)" % (self.employee, self.project, self.start_date, self.end_date)
 
 
class Entry(models.Model):
    category = models.ForeignKey(Category)
    date = models.DateField()
    name = models.ForeignKey(Person)
    amount = models.DecimalField(max_digits=8, decimal_places=2)
    bank_account = models.ForeignKey(BankAccount,related_name='paid_from',null=True,blank=True)
    memo = models.CharField(max_length=100,null=True,blank=True)
    
    def __str__(self):
        return "$%.2f | %s | %s" % (self.amount,self.name,self.date)
    class Meta:
        verbose_name_plural = 'Entries'
            
    class Admin:
        list_display = ('date', 'name', 'category', 'amount')
        date_hierarchy = 'date'
        search_fields = ('name','memo')
        list_filter = ('category','name','bank_account')