mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
Store used aliases in transactions
This commit is contained in:
@ -2,6 +2,7 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.db import models
|
||||
from django.db.models import F
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
@ -93,12 +94,26 @@ class Transaction(PolymorphicModel):
|
||||
related_name='+',
|
||||
verbose_name=_('source'),
|
||||
)
|
||||
|
||||
source_alias = models.CharField(
|
||||
max_length=255,
|
||||
default="", # Will be remplaced by the name of the note on save
|
||||
verbose_name=_('used alias'),
|
||||
)
|
||||
|
||||
destination = models.ForeignKey(
|
||||
Note,
|
||||
on_delete=models.PROTECT,
|
||||
related_name='+',
|
||||
verbose_name=_('destination'),
|
||||
)
|
||||
|
||||
destination_alias = models.CharField(
|
||||
max_length=255,
|
||||
default="", # Will be remplaced by the name of the note on save
|
||||
verbose_name=_('used alias'),
|
||||
)
|
||||
|
||||
created_at = models.DateTimeField(
|
||||
verbose_name=_('created at'),
|
||||
default=timezone.now,
|
||||
@ -142,6 +157,13 @@ class Transaction(PolymorphicModel):
|
||||
When saving, also transfer money between two notes
|
||||
"""
|
||||
|
||||
# If the aliases are not entered, we assume that the used alias is the name of the note
|
||||
if not self.source_alias:
|
||||
self.source_alias = str(self.source)
|
||||
|
||||
if not self.destination_alias:
|
||||
self.destination_alias = str(self.destination)
|
||||
|
||||
if self.source.pk == self.destination.pk:
|
||||
# When source == destination, no money is transfered
|
||||
super().save(*args, **kwargs)
|
||||
|
@ -21,11 +21,29 @@ class HistoryTable(tables.Table):
|
||||
'table table-condensed table-striped table-hover'
|
||||
}
|
||||
model = Transaction
|
||||
exclude = ("id", "polymorphic_ctype", "invalidity_reason")
|
||||
exclude = ("id", "polymorphic_ctype", "invalidity_reason", "source_alias", "destination_alias",)
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
sequence = ('...', 'type', 'total', 'valid',)
|
||||
orderable = False
|
||||
|
||||
source = tables.Column(
|
||||
attrs={
|
||||
"td": {
|
||||
"data-toggle": "tooltip",
|
||||
"title": lambda record: _("used alias").capitalize() + " : " + record.source_alias,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
destination = tables.Column(
|
||||
attrs={
|
||||
"td": {
|
||||
"data-toggle": "tooltip",
|
||||
"title": lambda record: _("used alias").capitalize() + " : " + record.destination_alias,
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
type = tables.Column()
|
||||
|
||||
total = tables.Column() # will use Transaction.total() !!
|
||||
|
Reference in New Issue
Block a user