society-self-service/sstreasury/models.py
2018-12-20 13:33:25 +11:00

71 lines
2.2 KiB
Python

# 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(null=True)
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])
state = models.IntegerField()
revenue = JSONField(default=[])
revenue_comments = models.TextField()
expense = JSONField(default=[])
expense_comments = models.TextField()
class Meta:
ordering = ['id']