2020-02-18 20:30:26 +00:00
|
|
|
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2019-08-15 21:08:15 +00:00
|
|
|
import django_tables2 as tables
|
2020-02-16 21:29:27 +00:00
|
|
|
from django.db.models import F
|
|
|
|
|
2019-08-15 21:08:15 +00:00
|
|
|
from .models.transactions import Transaction
|
2020-02-28 12:37:31 +00:00
|
|
|
from .models.notes import Alias
|
2019-08-15 21:08:15 +00:00
|
|
|
|
|
|
|
class HistoryTable(tables.Table):
|
|
|
|
class Meta:
|
2020-02-18 11:31:15 +00:00
|
|
|
attrs = {
|
|
|
|
'class':
|
2020-02-21 11:29:11 +00:00
|
|
|
'table table-condensed table-striped table-hover'
|
2020-02-18 11:31:15 +00:00
|
|
|
}
|
2019-08-15 21:08:15 +00:00
|
|
|
model = Transaction
|
2020-02-21 11:29:11 +00:00
|
|
|
template_name = 'django_tables2/bootstrap4.html'
|
2020-02-18 11:31:15 +00:00
|
|
|
sequence = ('...', 'total', 'valid')
|
2019-08-15 21:08:15 +00:00
|
|
|
|
2020-02-18 20:14:29 +00:00
|
|
|
total = tables.Column() # will use Transaction.total() !!
|
2019-08-15 21:08:15 +00:00
|
|
|
|
2020-02-18 20:14:29 +00:00
|
|
|
def order_total(self, queryset, is_descending):
|
2019-08-15 21:08:15 +00:00
|
|
|
# needed for rendering
|
2020-02-18 20:14:29 +00:00
|
|
|
queryset = queryset.annotate(total=F('amount') * F('quantity')) \
|
|
|
|
.order_by(('-' if is_descending else '') + 'total')
|
|
|
|
return (queryset, True)
|
2020-02-28 12:37:31 +00:00
|
|
|
|
|
|
|
class AliasTable(tables.Table):
|
|
|
|
class Meta:
|
|
|
|
attrs = {
|
|
|
|
'class':
|
|
|
|
'table table condensed table-striped table-hover'
|
|
|
|
}
|
|
|
|
model = Alias
|
|
|
|
fields = ('name',)
|
|
|
|
template_name = 'django_tables2/bootstrap4.html'
|
|
|
|
|
2020-02-28 12:49:50 +00:00
|
|
|
# delete = tables.LinkColumn('member:user_alias_delete', args=[A('id')], attrs={
|
|
|
|
# 'a': {'class': 'btn'} })
|