from django.db import models from django.utils.translation import gettext as _ from django.contrib.contenttypes.fields import GenericForeignKey from django.contrib.contenttypes.models import ContentType from .profiles import Profile class ExpenseTypeChoices(models.IntegerChoices): """Defines different types of expenses """ MONTHLY_FEE = (0, _("Monthly Fee")) SUPPORT = (1, _("Support")) DEVELOPMENT = (2, _("Custom Development")) COMMISSION = (3, _("Commission")) CONTRIBUTION = (4, _("Contribution")) OTHER = (99, _("Various Expenses")) class Expense(models.Model): """Contains information on an individual expense to be invoiced By relation to an Invoice model, this is simultaneously an invoice item """ expense_type = models.IntegerField( choices=ExpenseTypeChoices.choices, null=True, blank=True) text = models.CharField(max_length=256) payer = models.ForeignKey(Profile, models.PROTECT) """Of course, an Expense needs """ """An activity leading to an expense can have a starting and ending date (the day a reservation was made in case of per-reservation commissions, or the month for which a monthly fee is due) - but this is optional. """ datetime_from = models.DateTimeField(null=True, blank=True) datetime_to = models.DateTimeField(null=True, blank=True) """An expense can be related to any other object in the database – for example, it can be related to a Reservation object for a per-reservation commission, to a Restaurant object for its monthly fee, or to a Profile object for a per-user fee. This also allows easy reverse lookups to find out which expenses have occurred for which object. This is optional. """ object_type = models.ForeignKey( ContentType, on_delete=models.CASCADE, null=True) object_id = models.PositiveIntegerField(null=True, blank=True) related_object = GenericForeignKey('object_type', 'object_id', null=True)