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