From 40a7d3b2957d6aeac8e1914be755578592a43795 Mon Sep 17 00:00:00 2001 From: Benjamin Graillot Date: Sun, 23 Feb 2020 17:27:55 +0100 Subject: [PATCH] [note] TransactionCategory --> TemplateCategory --- apps/note/admin.py | 6 +++--- apps/note/fixtures/initial.json | 18 +++++++++--------- apps/note/models/__init__.py | 4 ++-- apps/note/models/transactions.py | 24 ++++++++++++++++++++++-- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/apps/note/admin.py b/apps/note/admin.py index f403dcd1..e8966d44 100644 --- a/apps/note/admin.py +++ b/apps/note/admin.py @@ -7,7 +7,7 @@ from polymorphic.admin import PolymorphicChildModelAdmin, \ PolymorphicChildModelFilter, PolymorphicParentModelAdmin 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): @@ -154,8 +154,8 @@ class TransactionTemplateAdmin(admin.ModelAdmin): poly_destination.short_description = _('destination') -@admin.register(TransactionCategory) -class TransactionCategoryAdmin(admin.ModelAdmin): +@admin.register(TemplateCategory) +class TemplateCategoryAdmin(admin.ModelAdmin): """ Admin customisation for TransactionTemplate """ diff --git a/apps/note/fixtures/initial.json b/apps/note/fixtures/initial.json index f853d3cb..c0e92bda 100644 --- a/apps/note/fixtures/initial.json +++ b/apps/note/fixtures/initial.json @@ -162,59 +162,59 @@ } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 1, "fields": { "name": "Soft" } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 2, "fields": { "name": "Pulls" } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 3, "fields": { "name": "Gala" } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 4, "fields": { "name": "Clubs" } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 5, "fields": { "name": "Bouffe" } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 6, "fields": { "name": "BDA" } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 7, "fields": { "name": "Autre" } }, { - "model": "note.transactioncategory", + "model": "note.templatecategory", "pk": 8, "fields": { "name": "Alcool" } } -] \ No newline at end of file +] diff --git a/apps/note/models/__init__.py b/apps/note/models/__init__.py index e372fc46..bac4f0ba 100644 --- a/apps/note/models/__init__.py +++ b/apps/note/models/__init__.py @@ -3,11 +3,11 @@ from .notes import Alias, Note, NoteClub, NoteSpecial, NoteUser from .transactions import MembershipTransaction, Transaction, \ - TransactionCategory, TransactionTemplate, TransactionType + TemplateCategory, TransactionTemplate, TransactionType __all__ = [ # Notes 'Alias', 'Note', 'NoteClub', 'NoteSpecial', 'NoteUser', # Transactions - 'MembershipTransaction', 'Transaction', 'TransactionCategory', 'TransactionTemplate','TransactionType', + 'MembershipTransaction', 'Transaction', 'TemplateCategory', 'TransactionTemplate','TransactionType', ] diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index d441785e..388efb3d 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -13,7 +13,7 @@ Defines transactions """ -class TransactionCategory(models.Model): +class TemplateCategory(models.Model): """ Defined a recurrent transaction category @@ -55,7 +55,7 @@ class TransactionTemplate(models.Model): help_text=_('in centimes'), ) category = models.ForeignKey( - TransactionCategory, + TemplateCategory, on_delete=models.PROTECT, verbose_name=_('type'), max_length=31, @@ -173,6 +173,26 @@ class Transaction(models.Model): 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): """ Special type of :model:`note.Transaction` associated to a :model:`member.Membership`.