1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-27 02:43:01 +00:00

add a TransactionType model

This commit is contained in:
Pierre-antoine Comby 2020-02-23 16:50:14 +01:00
parent f3ec0836f8
commit 126686ab03
3 changed files with 34 additions and 4 deletions

View File

@ -7,7 +7,7 @@ from polymorphic.admin import PolymorphicChildModelAdmin, \
PolymorphicChildModelFilter, PolymorphicParentModelAdmin PolymorphicChildModelFilter, PolymorphicParentModelAdmin
from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser from .models.notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
from .models.transactions import Transaction, TransactionCategory, TransactionTemplate from .models.transactions import Transaction, TransactionCategory, TransactionTemplate, TransactionType
class AliasInlines(admin.TabularInline): class AliasInlines(admin.TabularInline):
@ -161,3 +161,11 @@ class TransactionCategoryAdmin(admin.ModelAdmin):
""" """
list_display = ('name', ) list_display = ('name', )
list_filter = ('name', ) list_filter = ('name', )
@admin.register(TransactionType)
class TransactionTypeAdmin(admin.ModelAdmin):
"""
Admin customisation for TransactionTemplate
"""
list_display = ('name', )
list_filter = ('name', )

View File

@ -3,11 +3,11 @@
from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser
from .transactions import MembershipTransaction, Transaction, \ from .transactions import MembershipTransaction, Transaction, \
TransactionCategory, TransactionTemplate TransactionCategory, TransactionTemplate, TransactionType
__all__ = [ __all__ = [
# Notes # Notes
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser', 'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
# Transactions # Transactions
'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate', 'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate','TransactionType',
] ]

View File

@ -76,6 +76,26 @@ class TransactionTemplate(models.Model):
return reverse('note:template_update', args=(self.pk, )) 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(models.Model):
""" """
General transaction between two :model:`note.Note` General transaction between two :model:`note.Note`
@ -107,7 +127,9 @@ class Transaction(models.Model):
default=1, default=1,
) )
amount = models.PositiveIntegerField(verbose_name=_('amount'), ) amount = models.PositiveIntegerField(verbose_name=_('amount'), )
transaction_type = models.CharField( transaction_type = models.ForeignKey(
TransactionType,
on_delete=models.PROTECT,
verbose_name=_('type'), verbose_name=_('type'),
max_length=31, max_length=31,
) )