Ignore:
Timestamp:
Jan 5, 2010, 4:53:12 AM (16 years ago)
Author:
Alex Dehnert <adehnert@…>
Branches:
master, client
Children:
7874f6a
Parents:
719e4bb
git-author:
Alex Dehnert <adehnert@…> (01/05/10 04:53:12)
git-committer:
Alex Dehnert <adehnert@…> (01/05/10 04:53:12)
Message:

Bunch of work on the accounting system

File:
1 edited

Legend:

Unmodified
Added
Removed
  • treasury/vouchers/models.py

    r719e4bb r13a23ce  
    11from django.db import models
     2import treebeard.mp_tree
     3import settings
    24
    3 # Create your models here.
     5class BudgetArea(treebeard.mp_tree.MP_Node):
     6    name = models.CharField(max_length=50)
     7    comment = models.TextField(blank=True)
     8    always = models.BooleanField(blank=True, default=False)
     9
     10    # Contact / ACL information
     11    # If not specified, inherit from parent
     12    owner = models.EmailField(help_text = 'Email address of the officer responsible for the area', blank=True) # owner of the budget area
     13    interested = models.EmailField(help_text='Email address of parties interested in the area', blank=True) # interested parties (ie, whole committee)
     14    use_owner = models.BooleanField(default=False, blank=True)
     15
     16    def contact_address(self,):
     17        address = ''
     18        if self.use_owner:
     19            address = self.owner or self.interested
     20        else:
     21            address = self.interested or self.owner
     22        return address or self.get_parent().contact_address()
     23
     24    def mark_used(self, term, comment=""):
     25        BudgetAreaTerm.objects.get_or_create(
     26            budget_area=self,
     27            budget_term=term,
     28            defaults={'comment':comment}
     29        )
     30
     31    @classmethod
     32    def get_by_path(cls, path):
     33        root = BudgetArea.objects.get(name=path[0], depth=1)
     34        node = root
     35        for name in path[1:]:
     36            node = node.get_children().filter(name=name)[0]
     37        return node
     38
     39    def dump_to_html(self):
     40        struct = self.dump_bulk()
     41        return self.struct_to_html(struct, depth=0)
     42
     43    def struct_to_html(self, struct, depth=0):
     44        def format_data(data):
     45            return "<em>"+data['name']+"</em> "+unicode(data)
     46        prefix = "\t"*depth
     47        html = prefix+"<ul>\n"
     48        html = html + "\n".join(
     49            [("%(prefix)s\t<li>%(data)s\n%(children)s\t%(prefix)s</li>\n" % {
     50                'prefix':prefix,
     51                'data':format_data(elem['data']),
     52                'children':('children' in elem and self.struct_to_html(elem['children'], depth+1) or '')
     53            }) for elem in struct])
     54        html = html + prefix + "</ul>\n"
     55        return html
     56
     57    def __unicode__(self,):
     58        return u"%s [%s] (%s)" % (self.name, self.contact_address(), self.always, )
     59
     60class BudgetTerm(models.Model):
     61    name = models.CharField(max_length=20)
     62    start_date = models.DateField()
     63    end_date = models.DateField()
     64    submit_deadline = models.DateField()
     65
     66class BudgetAreaTerm(models.Model):
     67    budget_area = models.ForeignKey(BudgetArea)
     68    budget_term = models.ForeignKey(BudgetTerm)
     69    comment = models.TextField(blank=True, )
     70
     71class ReimbursementRequest(models.Model):
     72    submitter = models.CharField(max_length=10) # MIT username of submitter
     73    check_to_name = models.CharField(max_length=50)
     74    check_to_email = models.EmailField()
     75    check_to_addr = models.TextField(blank=True)
     76    amount = models.DecimalField(max_digits=7, decimal_places=2)
     77    budget_area = models.ForeignKey(BudgetArea)
     78    budget_term = models.ForeignKey(BudgetTerm)
     79
     80def coerce_full_email(email):
     81    if '@' in email: return email
     82    else: return email + '@' + settings.DEFAULT_DOMAIN
Note: See TracChangeset for help on using the changeset viewer.