[note] TransactionCategory --> TemplateCategory

This commit is contained in:
Benjamin Graillot 2020-02-23 17:27:55 +01:00
parent 126686ab03
commit 40a7d3b295
4 changed files with 36 additions and 16 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, TransactionType from .models.transactions import Transaction, TemplateCategory, TransactionTemplate, TransactionType
class AliasInlines(admin.TabularInline): class AliasInlines(admin.TabularInline):
@ -154,8 +154,8 @@ class TransactionTemplateAdmin(admin.ModelAdmin):
poly_destination.short_description = _('destination') poly_destination.short_description = _('destination')
@admin.register(TransactionCategory) @admin.register(TemplateCategory)
class TransactionCategoryAdmin(admin.ModelAdmin): class TemplateCategoryAdmin(admin.ModelAdmin):
""" """
Admin customisation for TransactionTemplate Admin customisation for TransactionTemplate
""" """

View File

@ -162,56 +162,56 @@
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 1, "pk": 1,
"fields": { "fields": {
"name": "Soft" "name": "Soft"
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 2, "pk": 2,
"fields": { "fields": {
"name": "Pulls" "name": "Pulls"
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 3, "pk": 3,
"fields": { "fields": {
"name": "Gala" "name": "Gala"
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 4, "pk": 4,
"fields": { "fields": {
"name": "Clubs" "name": "Clubs"
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 5, "pk": 5,
"fields": { "fields": {
"name": "Bouffe" "name": "Bouffe"
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 6, "pk": 6,
"fields": { "fields": {
"name": "BDA" "name": "BDA"
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 7, "pk": 7,
"fields": { "fields": {
"name": "Autre" "name": "Autre"
} }
}, },
{ {
"model": "note.transactioncategory", "model": "note.templatecategory",
"pk": 8, "pk": 8,
"fields": { "fields": {
"name": "Alcool" "name": "Alcool"

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, TransactionType TemplateCategory, TransactionTemplate, TransactionType
__all__ = [ __all__ = [
# Notes # Notes
'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser', 'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser',
# Transactions # Transactions
'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate','TransactionType', 'MembershipTransaction', 'Transaction', 'TemplateCategory', 'TransactionTemplate','TransactionType',
] ]

View File

@ -13,7 +13,7 @@ Defines transactions
""" """
class TransactionCategory(models.Model): class TemplateCategory(models.Model):
""" """
Defined a recurrent transaction category Defined a recurrent transaction category
@ -55,7 +55,7 @@ class TransactionTemplate(models.Model):
help_text=_('in centimes'), help_text=_('in centimes'),
) )
category = models.ForeignKey( category = models.ForeignKey(
TransactionCategory, TemplateCategory,
on_delete=models.PROTECT, on_delete=models.PROTECT,
verbose_name=_('type'), verbose_name=_('type'),
max_length=31, max_length=31,
@ -173,6 +173,26 @@ class Transaction(models.Model):
return self.amount * self.quantity return self.amount * self.quantity
class TemplateTransaction(Transaction):
"""
Special type of :model:`note.Transaction` associated to a :model:`note.TransactionTemplate`.
"""
template = models.ForeignKey(
TransactionTemplate,
null=True
on_delete=models.SET_NULL
)
category = models.ForeignKey(
TemplateCategory,
on_delete=models.PROTECT
)
name = models.CharField(
max_length=255
)
class MembershipTransaction(Transaction): class MembershipTransaction(Transaction):
""" """
Special type of :model:`note.Transaction` associated to a :model:`member.Membership`. Special type of :model:`note.Transaction` associated to a :model:`member.Membership`.