vafling/mercantile/models.py

48 lines
1.5 KiB
Python
Raw Normal View History

from django.db import models
2015-08-16 21:35:29 +02:00
from django.utils.translation import ugettext_lazy as _
2015-08-16 16:03:06 +02:00
from waffles.models import Event, UserProfile
2015-08-16 16:03:06 +02:00
2015-08-16 21:35:29 +02:00
class Debt(models.Model):
"""
The total debt owed by debtor to debtee.
2015-08-16 21:35:29 +02:00
If system is consistent this will be the sum of calculation.amount
and settlement.amount
"""
amount = models.BigIntegerField(verbose_name=_("Amount owed"))
debtor = models.ForeignKey(UserProfile, related_name="debtor", verbose_name=_("Debtor"))
debtee = models.ForeignKey(UserProfile, related_name="debtee", verbose_name=_("Debtee"))
2015-08-16 21:35:29 +02:00
class Meta:
verbose_name = _('Total debt')
verbose_name_plural = _('Total debts')
class Calculation(models.Model):
2015-08-16 21:35:29 +02:00
"""
This is a single calculation of debt from an event.
"""
debt = models.ForeignKey(Debt, verbose_name=_("Connected debt"))
event = models.ForeignKey(Event, _("Connected event"))
amount = models.IntegerField(verbose_name=_("Amount owed"))
date = models.DateTimeField(verbose_name=_("Date integrated"))
2015-08-16 21:35:29 +02:00
class Meta:
verbose_name = _('Calculation')
verbose_name_plural = _('Calculations')
2015-08-16 21:35:29 +02:00
class Settlement(models.Model):
"""
When part of or a whole debt is settled in 'cash'
"""
debt = models.ForeignKey(Debt, verbose_name=_("Connected debt"))
date = models.DateField(verbose_name=_("Date made"))
amount = models.IntegerField(verbose_name=_("Amount owed"))
class Meta:
verbose_name = _('Cash settlement')
verbose_name_plural = _('Cash settlements')