mirror of
https://gitlab.crans.org/bde/nk20
synced 2025-06-20 17:41:55 +02:00
Give a reason when a transaction is invalidated
This commit is contained in:
@ -115,11 +115,19 @@ class Transaction(PolymorphicModel):
|
||||
verbose_name=_('reason'),
|
||||
max_length=255,
|
||||
)
|
||||
|
||||
valid = models.BooleanField(
|
||||
verbose_name=_('valid'),
|
||||
default=True,
|
||||
)
|
||||
|
||||
invalidity_reason = models.CharField(
|
||||
verbose_name=_('invalidity reason'),
|
||||
max_length=255,
|
||||
default=None,
|
||||
null=True,
|
||||
)
|
||||
|
||||
class Meta:
|
||||
verbose_name = _("transaction")
|
||||
verbose_name_plural = _("transactions")
|
||||
@ -152,6 +160,10 @@ class Transaction(PolymorphicModel):
|
||||
self.source.balance -= to_transfer
|
||||
self.destination.balance += to_transfer
|
||||
|
||||
# When a transaction is declared valid, we ensure that the invalidity reason is null, if it was
|
||||
# previously invalid
|
||||
self.invalidity_reason = None
|
||||
|
||||
# We save first the transaction, in case of the user has no right to transfer money
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
|
@ -5,6 +5,7 @@ import html
|
||||
|
||||
import django_tables2 as tables
|
||||
from django.db.models import F
|
||||
from django.utils.html import format_html
|
||||
from django_tables2.utils import A
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
@ -20,19 +21,26 @@ class HistoryTable(tables.Table):
|
||||
'table table-condensed table-striped table-hover'
|
||||
}
|
||||
model = Transaction
|
||||
exclude = ("id", "polymorphic_ctype", )
|
||||
exclude = ("id", "polymorphic_ctype", "invalidity_reason")
|
||||
template_name = 'django_tables2/bootstrap4.html'
|
||||
sequence = ('...', 'type', 'total', 'valid', )
|
||||
sequence = ('...', 'type', 'total', 'valid',)
|
||||
orderable = False
|
||||
|
||||
type = tables.Column()
|
||||
|
||||
total = tables.Column() # will use Transaction.total() !!
|
||||
|
||||
valid = tables.Column(attrs={"td": {"id": lambda record: "validate_" + str(record.id),
|
||||
"class": lambda record: str(record.valid).lower() + ' validate',
|
||||
"onclick": lambda record: 'de_validate(' + str(record.id) + ', '
|
||||
+ str(record.valid).lower() + ')'}})
|
||||
valid = tables.Column(
|
||||
attrs={
|
||||
"td": {
|
||||
"id": lambda record: "validate_" + str(record.id),
|
||||
"class": lambda record: str(record.valid).lower() + ' validate',
|
||||
"onclick": lambda record: 'in_validate(' + str(record.id) + ', ' + str(record.valid).lower() + ')',
|
||||
"onmouseover": lambda record: 'hover_validation_btn(' + str(record.id) + ', true)',
|
||||
"onmouseout": lambda record: 'hover_validation_btn(' + str(record.id) + ', false)',
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
def order_total(self, queryset, is_descending):
|
||||
# needed for rendering
|
||||
@ -53,8 +61,13 @@ class HistoryTable(tables.Table):
|
||||
def render_reason(self, value):
|
||||
return html.unescape(value)
|
||||
|
||||
def render_valid(self, value):
|
||||
return "✔" if value else "✖"
|
||||
def render_valid(self, value, record):
|
||||
val = "✔" if value else "✖"
|
||||
val += "<br><input type='text' class='form-control' id='invalidity_reason_" + str(record.id) \
|
||||
+ "' value='" + (record.invalidity_reason.replace('\'', ''') if record.invalidity_reason else "") \
|
||||
+ "'" + ("" if value else " disabled") \
|
||||
+ " style='display: none;'>"
|
||||
return format_html(val)
|
||||
|
||||
|
||||
# function delete_button(id) provided in template file
|
||||
|
Reference in New Issue
Block a user