mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-21 09:58:23 +02:00
Polymorphic transaction
This commit is contained in:
committed by
Pierre-antoine Comby
parent
9207c5cdec
commit
c2fbb1bcdf
@ -5,6 +5,7 @@ from django.db import models
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.urls import reverse
|
||||
from polymorphic.models import PolymorphicModel
|
||||
|
||||
from .notes import Note, NoteClub
|
||||
|
||||
@ -77,27 +78,7 @@ class TransactionTemplate(models.Model):
|
||||
return reverse('note:template_update', args=(self.pk, ))
|
||||
|
||||
|
||||
class TransactionType(models.Model):
|
||||
"""
|
||||
Defined a recurrent transaction category
|
||||
|
||||
Example: food, softs, ...
|
||||
"""
|
||||
name = models.CharField(
|
||||
verbose_name=_("name"),
|
||||
max_length=31,
|
||||
unique=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("transaction type")
|
||||
verbose_name_plural = _("transaction types")
|
||||
|
||||
def __str__(self):
|
||||
return str(self.name)
|
||||
|
||||
|
||||
class Transaction(models.Model):
|
||||
class Transaction(PolymorphicModel):
|
||||
"""
|
||||
General transaction between two :model:`note.Note`
|
||||
|
||||
@ -128,12 +109,6 @@ class Transaction(models.Model):
|
||||
default=1,
|
||||
)
|
||||
amount = models.PositiveIntegerField(verbose_name=_('amount'), )
|
||||
transaction_type = models.ForeignKey(
|
||||
TransactionType,
|
||||
on_delete=models.PROTECT,
|
||||
verbose_name=_('type'),
|
||||
max_length=31,
|
||||
)
|
||||
reason = models.CharField(
|
||||
verbose_name=_('reason'),
|
||||
max_length=255,
|
||||
|
Reference in New Issue
Block a user