society-self-service/sstreasury/models.py

71 lines
2.2 KiB
Python
Raw Normal View History

2018-06-26 20:14:16 +10:00
# Society Self-Service
# Copyright © 2018 Yingtong Li (RunasSudo)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
from django.contrib.auth.models import User
from django.db import models
from jsonfield import JSONField
from enum import Enum
class Budget(models.Model):
pass
class BudgetComment(models.Model):
budget = models.ForeignKey(Budget, on_delete=models.CASCADE)
author = models.ForeignKey(User, on_delete=models.PROTECT, related_name='+')
time = models.DateTimeField()
content = models.TextField()
class Meta:
ordering = ['id']
class BudgetState(Enum):
DRAFT = 10, 'Draft'
RESUBMIT = 20, 'Returned for redrafting'
AWAIT_REVIEW = 30, 'Awaiting Treasury review'
ENDORSED = 40, 'Endorsed by Treasury, awaiting committee approval'
APPROVED = 50, 'Approved'
CANCELLED = 60, 'Cancelled'
def __new__(cls, value, description):
obj = object.__new__(cls)
obj._value_ = value
obj.description = description
return obj
class BudgetRevision(models.Model):
budget = models.ForeignKey(Budget, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
date = models.DateField()
2018-06-26 20:14:16 +10:00
contributors = models.ManyToManyField(User, related_name='+')
comments = models.TextField()
author = models.ForeignKey(User, on_delete=models.PROTECT, related_name='+')
time = models.DateTimeField()
state = models.IntegerField(choices=[(v.value, v.description) for v in BudgetState])
2018-06-26 20:14:16 +10:00
revenue = JSONField(default=[])
revenue_comments = models.TextField()
expense = JSONField(default=[])
expense_no_emergency_fund = models.BooleanField()
2018-06-26 20:14:16 +10:00
expense_comments = models.TextField()
class Meta:
ordering = ['id']