1 | from django.db import models |
---|
2 | import settings |
---|
3 | from finance_core.models import BudgetArea, BudgetTerm |
---|
4 | |
---|
5 | import datetime |
---|
6 | |
---|
7 | APPROVAL_STATE_PENDING = 0 |
---|
8 | APPROVAL_STATE_APPROVED = 1 |
---|
9 | APPROVAL_STATE_REJECTED = -1 |
---|
10 | APPROVAL_STATES = ( |
---|
11 | (APPROVAL_STATE_PENDING, 'Pending'), |
---|
12 | (APPROVAL_STATE_APPROVED, 'Approved'), |
---|
13 | (APPROVAL_STATE_REJECTED, 'Rejected'), |
---|
14 | ) |
---|
15 | |
---|
16 | class ReimbursementRequest(models.Model): |
---|
17 | submitter = models.CharField(max_length=10) # MIT username of submitter |
---|
18 | check_to_first_name = models.CharField(max_length=50, verbose_name="check recipient's first name") |
---|
19 | check_to_last_name = models.CharField(max_length=50, verbose_name="check recipient's last name") |
---|
20 | check_to_email = models.EmailField(verbose_name="email address for check pickup") |
---|
21 | check_to_addr = models.TextField(blank=True, verbose_name="address for check mailing", help_text="For most requests, this should be blank for pickup in SAO (W20-549)") |
---|
22 | amount = models.DecimalField(max_digits=7, decimal_places=2, help_text='Do not include "$"') |
---|
23 | budget_area = models.ForeignKey(BudgetArea, related_name='as_budget_area') |
---|
24 | budget_term = models.ForeignKey(BudgetTerm) |
---|
25 | expense_area = models.ForeignKey(BudgetArea, related_name='as_expense_area') # ~GL |
---|
26 | request_time = models.DateTimeField(default=datetime.datetime.now) |
---|
27 | approval_time = models.DateTimeField(blank=True, null=True,) |
---|
28 | approval_status = models.IntegerField(default=0, choices=APPROVAL_STATES) |
---|
29 | printing_time = models.DateTimeField(blank=True, null=True,) |
---|
30 | name = models.CharField(max_length=50, verbose_name='short description', ) |
---|
31 | description = models.TextField(blank=True, verbose_name='long description', ) |
---|
32 | |
---|
33 | class Meta: |
---|
34 | permissions = ( |
---|
35 | ('can_list', 'Can list requests',), |
---|
36 | ('can_approve', 'Can approve requests',), |
---|
37 | ) |
---|
38 | |
---|
39 | def __unicode__(self, ): |
---|
40 | return "%s: %s %s (%s) (by %s) for $%s" % ( |
---|
41 | self.name, |
---|
42 | self.check_to_first_name, |
---|
43 | self.check_to_last_name, |
---|
44 | self.check_to_email, |
---|
45 | self.submitter, |
---|
46 | self.amount, |
---|
47 | ) |
---|
48 | |
---|
49 | def convert(self, signatory, signatory_email=settings.SIGNATORY_EMAIL): |
---|
50 | voucher = Voucher() |
---|
51 | voucher.group_name = settings.GROUP_NAME |
---|
52 | voucher.account = self.budget_area.get_account_number() |
---|
53 | voucher.signatory = signatory |
---|
54 | voucher.signatory_email = signatory_email |
---|
55 | voucher.first_name = self.check_to_first_name |
---|
56 | voucher.last_name = self.check_to_last_name |
---|
57 | voucher.email_address = self.check_to_email |
---|
58 | voucher.mailing_address = self.check_to_addr |
---|
59 | voucher.amount = self.amount |
---|
60 | voucher.description = self.name |
---|
61 | voucher.gl = self.expense_area.get_account_number() |
---|
62 | voucher.save() |
---|
63 | self.approval_status = 1 |
---|
64 | self.approval_time = datetime.datetime.now() |
---|
65 | self.save() |
---|
66 | |
---|
67 | class Voucher(models.Model): |
---|
68 | group_name = models.CharField(max_length=10) |
---|
69 | account = models.IntegerField() |
---|
70 | signatory = models.CharField(max_length=50) |
---|
71 | signatory_email = models.EmailField() |
---|
72 | first_name = models.CharField(max_length=20) |
---|
73 | last_name = models.CharField(max_length=20) |
---|
74 | email_address = models.EmailField(max_length=50) |
---|
75 | mailing_address = models.TextField() |
---|
76 | amount = models.DecimalField(max_digits=7, decimal_places=2,) |
---|
77 | description = models.TextField() |
---|
78 | gl = models.IntegerField() |
---|