Add transaction type field

This commit is contained in:
Yohann D'ANELLO 2020-03-16 12:11:16 +01:00 committed by Bombar Maxime
parent a1f37f0eea
commit 7b98244360
8 changed files with 245 additions and 195 deletions

View File

@ -107,7 +107,24 @@ class Transaction(PolymorphicModel):
verbose_name=_('quantity'), verbose_name=_('quantity'),
default=1, default=1,
) )
amount = models.PositiveIntegerField(verbose_name=_('amount'), ) amount = models.PositiveIntegerField(
verbose_name=_('amount'),
)
type = models.CharField(
verbose_name=_('type'),
choices=(
('gift', _('Gift')),
('transfer', _('Transfer')),
('template', _('Template')),
('credit', _('Credit')),
('debit', _('Debit')),
('membership', _('membership transaction')),
),
default='transfer',
max_length=10,
)
reason = models.CharField( reason = models.CharField(
verbose_name=_('reason'), verbose_name=_('reason'),
max_length=255, max_length=255,
@ -158,10 +175,6 @@ class Transaction(PolymorphicModel):
def total(self): def total(self):
return self.amount * self.quantity return self.amount * self.quantity
@property
def type(self):
return _('transfer')
class TemplateTransaction(Transaction): class TemplateTransaction(Transaction):
""" """
@ -178,10 +191,6 @@ class TemplateTransaction(Transaction):
on_delete=models.PROTECT, on_delete=models.PROTECT,
) )
@property
def type(self):
return _('template')
class SpecialTransaction(Transaction): class SpecialTransaction(Transaction):
""" """
@ -200,7 +209,8 @@ class SpecialTransaction(Transaction):
bank = models.CharField( bank = models.CharField(
max_length=255, max_length=255,
verbose_name=_("bank") verbose_name=_("bank"),
blank=True,
) )
@ -219,7 +229,3 @@ class MembershipTransaction(Transaction):
class Meta: class Meta:
verbose_name = _("membership transaction") verbose_name = _("membership transaction")
verbose_name_plural = _("membership transactions") verbose_name_plural = _("membership transactions")
@property
def type(self):
return _('membership')

View File

@ -6,6 +6,7 @@ import html
import django_tables2 as tables import django_tables2 as tables
from django.db.models import F from django.db.models import F
from django_tables2.utils import A from django_tables2.utils import A
from django.utils.translation import gettext_lazy as _
from .models.notes import Alias from .models.notes import Alias
from .models.transactions import Transaction from .models.transactions import Transaction
@ -21,9 +22,11 @@ class HistoryTable(tables.Table):
model = Transaction model = Transaction
exclude = ("id", "polymorphic_ctype", ) exclude = ("id", "polymorphic_ctype", )
template_name = 'django_tables2/bootstrap4.html' template_name = 'django_tables2/bootstrap4.html'
sequence = ('...', 'total', 'valid', ) sequence = ('...', 'type', 'total', 'valid', )
orderable = False orderable = False
type = tables.Column()
total = tables.Column() # will use Transaction.total() !! total = tables.Column() # will use Transaction.total() !!
valid = tables.Column(attrs={"td": {"id": lambda record: "validate_" + str(record.id), valid = tables.Column(attrs={"td": {"id": lambda record: "validate_" + str(record.id),
@ -43,6 +46,9 @@ class HistoryTable(tables.Table):
def render_total(self, value): def render_total(self, value):
return pretty_money(value) return pretty_money(value)
def render_type(self, value):
return _(value)
# Django-tables escape strings. That's a wrong thing. # Django-tables escape strings. That's a wrong thing.
def render_reason(self, value): def render_reason(self, value):
return html.unescape(value) return html.unescape(value)

View File

@ -6,7 +6,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.contenttypes.models import ContentType from django.contrib.contenttypes.models import ContentType
from django.db.models import Q from django.db.models import Q
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.views.generic import CreateView, ListView, UpdateView, TemplateView from django.views.generic import CreateView, ListView, UpdateView
from django_tables2 import SingleTableView from django_tables2 import SingleTableView
from .forms import TransactionTemplateForm from .forms import TransactionTemplateForm
@ -15,14 +15,19 @@ from .models.transactions import SpecialTransaction
from .tables import HistoryTable from .tables import HistoryTable
class TransactionCreate(LoginRequiredMixin, TemplateView): class TransactionCreate(LoginRequiredMixin, SingleTableView):
""" """
Show transfer page Show transfer page
TODO: If user have sufficient rights, they can transfer from an other note TODO: If user have sufficient rights, they can transfer from an other note
""" """
queryset = Transaction.objects.order_by("-id").all()[:50]
template_name = "note/transaction_form.html" template_name = "note/transaction_form.html"
# Transaction history table
table_class = HistoryTable
table_pagination = {"per_page": 50}
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
""" """
Add some context variables in template such as page title Add some context variables in template such as page title

View File

@ -8,7 +8,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-14 17:20+0100\n" "POT-Creation-Date: 2020-03-16 11:53+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -25,7 +25,7 @@ msgstr ""
#: apps/activity/models.py:19 apps/activity/models.py:44 #: apps/activity/models.py:19 apps/activity/models.py:44
#: apps/member/models.py:61 apps/member/models.py:112 #: apps/member/models.py:61 apps/member/models.py:112
#: apps/note/models/notes.py:188 apps/note/models/transactions.py:24 #: apps/note/models/notes.py:188 apps/note/models/transactions.py:24
#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:184 #: apps/note/models/transactions.py:44 apps/note/models/transactions.py:202
#: templates/member/profile_detail.html:15 #: templates/member/profile_detail.html:15
msgid "name" msgid "name"
msgstr "" msgstr ""
@ -51,7 +51,7 @@ msgid "description"
msgstr "" msgstr ""
#: apps/activity/models.py:54 apps/note/models/notes.py:164 #: apps/activity/models.py:54 apps/note/models/notes.py:164
#: apps/note/models/transactions.py:62 #: apps/note/models/transactions.py:62 apps/note/models/transactions.py:115
msgid "type" msgid "type"
msgstr "" msgstr ""
@ -254,12 +254,12 @@ msgstr ""
msgid "Alias successfully deleted" msgid "Alias successfully deleted"
msgstr "" msgstr ""
#: apps/note/admin.py:120 apps/note/models/transactions.py:93 #: apps/note/admin.py:120 apps/note/models/transactions.py:94
msgid "source" msgid "source"
msgstr "" msgstr ""
#: apps/note/admin.py:128 apps/note/admin.py:156 #: apps/note/admin.py:128 apps/note/admin.py:156
#: apps/note/models/transactions.py:53 apps/note/models/transactions.py:99 #: apps/note/models/transactions.py:53 apps/note/models/transactions.py:100
msgid "destination" msgid "destination"
msgstr "" msgstr ""
@ -309,7 +309,7 @@ msgstr ""
msgid "display image" msgid "display image"
msgstr "" msgstr ""
#: apps/note/models/notes.py:53 apps/note/models/transactions.py:102 #: apps/note/models/notes.py:53 apps/note/models/transactions.py:103
msgid "created at" msgid "created at"
msgstr "" msgstr ""
@ -395,7 +395,7 @@ msgstr ""
msgid "A template with this name already exist" msgid "A template with this name already exist"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:56 apps/note/models/transactions.py:109 #: apps/note/models/transactions.py:56 apps/note/models/transactions.py:111
msgid "amount" msgid "amount"
msgstr "" msgstr ""
@ -403,47 +403,69 @@ msgstr ""
msgid "in centimes" msgid "in centimes"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:74 #: apps/note/models/transactions.py:75
msgid "transaction template" msgid "transaction template"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:75 #: apps/note/models/transactions.py:76
msgid "transaction templates" msgid "transaction templates"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:106 #: apps/note/models/transactions.py:107
msgid "quantity" msgid "quantity"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:111 #: apps/note/models/transactions.py:117 templates/note/transaction_form.html:15
msgid "reason" msgid "Gift"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:115 #: apps/note/models/transactions.py:118 templates/base.html:90
msgid "valid" #: templates/note/transaction_form.html:19
#: templates/note/transaction_form.html:126
msgid "Transfer"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:120 #: apps/note/models/transactions.py:119
msgid "transaction" msgid "Template"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:121 #: apps/note/models/transactions.py:120 templates/note/transaction_form.html:23
msgid "transactions" msgid "Credit"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:189 #: apps/note/models/transactions.py:121 templates/note/transaction_form.html:27
msgid "first_name" msgid "Debit"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:194 #: apps/note/models/transactions.py:122 apps/note/models/transactions.py:230
msgid "bank"
msgstr ""
#: apps/note/models/transactions.py:211
msgid "membership transaction" msgid "membership transaction"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:129
msgid "reason"
msgstr ""
#: apps/note/models/transactions.py:133
msgid "valid"
msgstr ""
#: apps/note/models/transactions.py:138
msgid "transaction"
msgstr ""
#: apps/note/models/transactions.py:139
msgid "transactions"
msgstr ""
#: apps/note/models/transactions.py:207
msgid "first_name"
msgstr ""
#: apps/note/models/transactions.py:212 #: apps/note/models/transactions.py:212
msgid "bank"
msgstr ""
#: apps/note/models/transactions.py:231
msgid "membership transactions" msgid "membership transactions"
msgstr "" msgstr ""
@ -451,7 +473,7 @@ msgstr ""
msgid "Transfer money" msgid "Transfer money"
msgstr "" msgstr ""
#: apps/note/views.py:129 templates/base.html:71 #: apps/note/views.py:132 templates/base.html:78
msgid "Consumptions" msgid "Consumptions"
msgstr "" msgstr ""
@ -478,23 +500,18 @@ msgstr ""
msgid "The ENS Paris-Saclay BDE note." msgid "The ENS Paris-Saclay BDE note."
msgstr "" msgstr ""
#: templates/base.html:74 #: templates/base.html:81
msgid "Clubs" msgid "Clubs"
msgstr "" msgstr ""
#: templates/base.html:77 #: templates/base.html:84
msgid "Activities" msgid "Activities"
msgstr "" msgstr ""
#: templates/base.html:80 #: templates/base.html:87
msgid "Buttons" msgid "Buttons"
msgstr "" msgstr ""
#: templates/base.html:83 templates/note/transaction_form.html:19
#: templates/note/transaction_form.html:126
msgid "Transfer"
msgstr ""
#: templates/cas_server/base.html:7 #: templates/cas_server/base.html:7
msgid "Central Authentication Service" msgid "Central Authentication Service"
msgstr "" msgstr ""
@ -644,42 +661,30 @@ msgstr ""
msgid "Select consumptions" msgid "Select consumptions"
msgstr "" msgstr ""
#: templates/note/conso_form.html:50 #: templates/note/conso_form.html:51
msgid "Consume!" msgid "Consume!"
msgstr "" msgstr ""
#: templates/note/conso_form.html:62 #: templates/note/conso_form.html:64
msgid "The most used buttons will display here." msgid "Most used buttons"
msgstr "" msgstr ""
#: templates/note/conso_form.html:107 #: templates/note/conso_form.html:121
msgid "Edit" msgid "Edit"
msgstr "" msgstr ""
#: templates/note/conso_form.html:112 #: templates/note/conso_form.html:126
msgid "Single consumptions" msgid "Single consumptions"
msgstr "" msgstr ""
#: templates/note/conso_form.html:116 #: templates/note/conso_form.html:130
msgid "Double consumptions" msgid "Double consumptions"
msgstr "" msgstr ""
#: templates/note/conso_form.html:127 #: templates/note/conso_form.html:141
msgid "Recent transactions history" msgid "Recent transactions history"
msgstr "" msgstr ""
#: templates/note/transaction_form.html:15
msgid "Gift"
msgstr ""
#: templates/note/transaction_form.html:23
msgid "Credit"
msgstr ""
#: templates/note/transaction_form.html:27
msgid "Debit"
msgstr ""
#: templates/note/transaction_form.html:55 #: templates/note/transaction_form.html:55
msgid "External payment" msgid "External payment"
msgstr "" msgstr ""

View File

@ -3,7 +3,7 @@ msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n" "Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-03-14 17:20+0100\n" "POT-Creation-Date: 2020-03-16 11:53+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -20,7 +20,7 @@ msgstr "activité"
#: apps/activity/models.py:19 apps/activity/models.py:44 #: apps/activity/models.py:19 apps/activity/models.py:44
#: apps/member/models.py:61 apps/member/models.py:112 #: apps/member/models.py:61 apps/member/models.py:112
#: apps/note/models/notes.py:188 apps/note/models/transactions.py:24 #: apps/note/models/notes.py:188 apps/note/models/transactions.py:24
#: apps/note/models/transactions.py:44 apps/note/models/transactions.py:184 #: apps/note/models/transactions.py:44 apps/note/models/transactions.py:202
#: templates/member/profile_detail.html:15 #: templates/member/profile_detail.html:15
msgid "name" msgid "name"
msgstr "nom" msgstr "nom"
@ -46,7 +46,7 @@ msgid "description"
msgstr "description" msgstr "description"
#: apps/activity/models.py:54 apps/note/models/notes.py:164 #: apps/activity/models.py:54 apps/note/models/notes.py:164
#: apps/note/models/transactions.py:62 #: apps/note/models/transactions.py:62 apps/note/models/transactions.py:115
msgid "type" msgid "type"
msgstr "type" msgstr "type"
@ -253,12 +253,12 @@ msgstr "Compte n°%(id)s : %(username)s"
msgid "Alias successfully deleted" msgid "Alias successfully deleted"
msgstr "L'alias a bien été supprimé" msgstr "L'alias a bien été supprimé"
#: apps/note/admin.py:120 apps/note/models/transactions.py:93 #: apps/note/admin.py:120 apps/note/models/transactions.py:94
msgid "source" msgid "source"
msgstr "source" msgstr "source"
#: apps/note/admin.py:128 apps/note/admin.py:156 #: apps/note/admin.py:128 apps/note/admin.py:156
#: apps/note/models/transactions.py:53 apps/note/models/transactions.py:99 #: apps/note/models/transactions.py:53 apps/note/models/transactions.py:100
msgid "destination" msgid "destination"
msgstr "destination" msgstr "destination"
@ -309,7 +309,7 @@ msgstr ""
msgid "display image" msgid "display image"
msgstr "image affichée" msgstr "image affichée"
#: apps/note/models/notes.py:53 apps/note/models/transactions.py:102 #: apps/note/models/notes.py:53 apps/note/models/transactions.py:103
msgid "created at" msgid "created at"
msgstr "créée le" msgstr "créée le"
@ -395,7 +395,7 @@ msgstr "catégories de transaction"
msgid "A template with this name already exist" msgid "A template with this name already exist"
msgstr "Un modèle de transaction avec un nom similaire existe déjà." msgstr "Un modèle de transaction avec un nom similaire existe déjà."
#: apps/note/models/transactions.py:56 apps/note/models/transactions.py:109 #: apps/note/models/transactions.py:56 apps/note/models/transactions.py:111
msgid "amount" msgid "amount"
msgstr "montant" msgstr "montant"
@ -403,47 +403,69 @@ msgstr "montant"
msgid "in centimes" msgid "in centimes"
msgstr "en centimes" msgstr "en centimes"
#: apps/note/models/transactions.py:74 #: apps/note/models/transactions.py:75
msgid "transaction template" msgid "transaction template"
msgstr "modèle de transaction" msgstr "modèle de transaction"
#: apps/note/models/transactions.py:75 #: apps/note/models/transactions.py:76
msgid "transaction templates" msgid "transaction templates"
msgstr "modèles de transaction" msgstr "modèles de transaction"
#: apps/note/models/transactions.py:106 #: apps/note/models/transactions.py:107
msgid "quantity" msgid "quantity"
msgstr "quantité" msgstr "quantité"
#: apps/note/models/transactions.py:111 #: apps/note/models/transactions.py:117 templates/note/transaction_form.html:15
msgid "reason" msgid "Gift"
msgstr "raison" msgstr "Don"
#: apps/note/models/transactions.py:115 #: apps/note/models/transactions.py:118 templates/base.html:90
msgid "valid" #: templates/note/transaction_form.html:19
msgstr "valide" #: templates/note/transaction_form.html:126
msgid "Transfer"
msgstr "Virement"
#: apps/note/models/transactions.py:120 #: apps/note/models/transactions.py:119
msgid "transaction" msgid "Template"
msgstr "transaction" msgstr "Bouton"
#: apps/note/models/transactions.py:121 #: apps/note/models/transactions.py:120 templates/note/transaction_form.html:23
msgid "transactions" msgid "Credit"
msgstr "transactions" msgstr "Crédit"
#: apps/note/models/transactions.py:189 #: apps/note/models/transactions.py:121 templates/note/transaction_form.html:27
msgid "first_name" msgid "Debit"
msgstr "" msgstr "Retrait"
#: apps/note/models/transactions.py:194 #: apps/note/models/transactions.py:122 apps/note/models/transactions.py:230
msgid "bank"
msgstr ""
#: apps/note/models/transactions.py:211
msgid "membership transaction" msgid "membership transaction"
msgstr "transaction d'adhésion" msgstr "transaction d'adhésion"
#: apps/note/models/transactions.py:129
msgid "reason"
msgstr "raison"
#: apps/note/models/transactions.py:133
msgid "valid"
msgstr "valide"
#: apps/note/models/transactions.py:138
msgid "transaction"
msgstr "transaction"
#: apps/note/models/transactions.py:139
msgid "transactions"
msgstr "transactions"
#: apps/note/models/transactions.py:207
msgid "first_name"
msgstr "Prénom"
#: apps/note/models/transactions.py:212 #: apps/note/models/transactions.py:212
msgid "bank"
msgstr "Banque"
#: apps/note/models/transactions.py:231
msgid "membership transactions" msgid "membership transactions"
msgstr "transactions d'adhésion" msgstr "transactions d'adhésion"
@ -451,7 +473,7 @@ msgstr "transactions d'adhésion"
msgid "Transfer money" msgid "Transfer money"
msgstr "Transferts d'argent" msgstr "Transferts d'argent"
#: apps/note/views.py:129 templates/base.html:71 #: apps/note/views.py:132 templates/base.html:78
msgid "Consumptions" msgid "Consumptions"
msgstr "Consommations" msgstr "Consommations"
@ -478,23 +500,18 @@ msgstr ""
msgid "The ENS Paris-Saclay BDE note." msgid "The ENS Paris-Saclay BDE note."
msgstr "La note du BDE de l'ENS Paris-Saclay." msgstr "La note du BDE de l'ENS Paris-Saclay."
#: templates/base.html:74 #: templates/base.html:81
msgid "Clubs" msgid "Clubs"
msgstr "Clubs" msgstr "Clubs"
#: templates/base.html:77 #: templates/base.html:84
msgid "Activities" msgid "Activities"
msgstr "Activités" msgstr "Activités"
#: templates/base.html:80 #: templates/base.html:87
msgid "Buttons" msgid "Buttons"
msgstr "Boutons" msgstr "Boutons"
#: templates/base.html:83 templates/note/transaction_form.html:19
#: templates/note/transaction_form.html:126
msgid "Transfer"
msgstr "Virement"
#: templates/cas_server/base.html:7 #: templates/cas_server/base.html:7
msgid "Central Authentication Service" msgid "Central Authentication Service"
msgstr "" msgstr ""
@ -555,7 +572,7 @@ msgstr ""
#: templates/django_filters/rest_framework/form.html:5 #: templates/django_filters/rest_framework/form.html:5
#: templates/member/club_form.html:10 #: templates/member/club_form.html:10
msgid "Submit" msgid "Submit"
msgstr "" msgstr "Envoyer"
#: templates/member/club_detail.html:10 #: templates/member/club_detail.html:10
msgid "Membership starts on" msgid "Membership starts on"
@ -646,43 +663,30 @@ msgstr "Sélection des émetteurs"
msgid "Select consumptions" msgid "Select consumptions"
msgstr "Consommations" msgstr "Consommations"
#: templates/note/conso_form.html:50 #: templates/note/conso_form.html:51
msgid "Consume!" msgid "Consume!"
msgstr "Consommer !" msgstr "Consommer !"
#: templates/note/conso_form.html:62 #: templates/note/conso_form.html:64
msgid "Most used buttons" msgid "Most used buttons"
msgstr "Boutons les plus utilisés" msgstr "Boutons les plus utilisés"
#: templates/note/conso_form.html:107 #: templates/note/conso_form.html:121
msgid "Edit" msgid "Edit"
msgstr "Éditer" msgstr "Éditer"
#: templates/note/conso_form.html:112 #: templates/note/conso_form.html:126
#| msgid "Consumptions"
msgid "Single consumptions" msgid "Single consumptions"
msgstr "Consos simples" msgstr "Consos simples"
#: templates/note/conso_form.html:116 #: templates/note/conso_form.html:130
msgid "Double consumptions" msgid "Double consumptions"
msgstr "Consos doubles" msgstr "Consos doubles"
#: templates/note/conso_form.html:127 #: templates/note/conso_form.html:141
msgid "Recent transactions history" msgid "Recent transactions history"
msgstr "Historique des transactions récentes" msgstr "Historique des transactions récentes"
#: templates/note/transaction_form.html:15
msgid "Gift"
msgstr "Don"
#: templates/note/transaction_form.html:23
msgid "Credit"
msgstr "Crédit"
#: templates/note/transaction_form.html:27
msgid "Debit"
msgstr "Retrait"
#: templates/note/transaction_form.html:55 #: templates/note/transaction_form.html:55
msgid "External payment" msgid "External payment"
msgstr "Paiement extérieur" msgstr "Paiement extérieur"

View File

@ -15,6 +15,18 @@ function pretty_money(value) {
+ (Math.abs(value) % 100 < 10 ? "0" : "") + (Math.abs(value) % 100) + " €"; + (Math.abs(value) % 100 < 10 ? "0" : "") + (Math.abs(value) % 100) + " €";
} }
/**
* Add a message on the top of the page.
* @param msg The message to display
* @param alert_type The type of the alert. Choices: info, success, warning, danger
*/
function addMsg(msg, alert_type) {
let msgDiv = $("#messages");
let html = msgDiv.html();
html += "<div class=\"alert alert-" + alert_type + "\">" + msg + "</div>\n";
msgDiv.html(html);
}
/** /**
* Reload the balance of the user on the right top corner * Reload the balance of the user on the right top corner
*/ */
@ -256,11 +268,8 @@ function de_validate(id, validated) {
refreshHistory(); refreshHistory();
}, },
error: function(err) { error: function(err) {
let msgDiv = $("#messages"); addMsg("Une erreur est survenue lors de la validation/dévalidation " +
let html = msgDiv.html(); "de cette transaction : " + err.responseText, "danger");
html += "<div class='alert alert-danger'>Une erreur est survenue lors de la validation/dévalidation " +
"de cette transaction : " + err.responseText + "</div>";
msgDiv.html(html);
refreshBalance(); refreshBalance();
// error if this method doesn't exist. Please define it. // error if this method doesn't exist. Please define it.

View File

@ -128,6 +128,22 @@ function addConso(dest, amount, type, category_id, category_name, template_id, t
consumeAll(); consumeAll();
} }
/**
* Reset the page as its initial state.
*/
function reset() {
notes_display.length = 0;
notes.length = 0;
buttons.length = 0;
$("#note_list").html("");
$("#alias_matched").html("");
$("#consos_list").html("");
displayNote(null, "");
refreshHistory();
refreshBalance();
}
/** /**
* Apply all transactions: all notes in `notes` buy each item in `buttons` * Apply all transactions: all notes in `notes` buy each item in `buttons`
*/ */
@ -161,19 +177,14 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
"valid": true, "valid": true,
"polymorphic_ctype": type, "polymorphic_ctype": type,
"resourcetype": "TemplateTransaction", "resourcetype": "TemplateTransaction",
"type": "template",
"source": source, "source": source,
"destination": dest, "destination": dest,
"category": category, "category": category,
"template": template "template": template
}, function() { }, reset).fail(function (e) {
notes_display.length = 0; reset();
notes.length = 0;
buttons.length = 0; addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger");
$("#note_list").html(""); });
$("#alias_matched").html("");
$("#consos_list").html("");
displayNote(null, "");
refreshHistory();
refreshBalance();
});
} }

View File

@ -3,7 +3,7 @@
SPDX-License-Identifier: GPL-2.0-or-later SPDX-License-Identifier: GPL-2.0-or-later
{% endcomment %} {% endcomment %}
{% load i18n static %} {% load i18n static django_tables2 %}
{% block content %} {% block content %}
@ -126,6 +126,15 @@ SPDX-License-Identifier: GPL-2.0-or-later
<button id="transfer" class="form-control btn btn-primary">{% trans 'Transfer' %}</button> <button id="transfer" class="form-control btn btn-primary">{% trans 'Transfer' %}</button>
</div> </div>
</div> </div>
<div class="card shadow mb-4" id="history">
<div class="card-header">
<p class="card-text font-weight-bold">
{% trans "Recent transactions history" %}
</p>
</div>
{% render_table table %}
</div>
{% endblock %} {% endblock %}
{% block extrajavascript %} {% block extrajavascript %}
@ -135,6 +144,10 @@ SPDX-License-Identifier: GPL-2.0-or-later
dests = []; dests = [];
dests_notes_display = []; dests_notes_display = [];
function refreshHistory() {
$("#history").load("/note/transfer/ #history");
}
function reset() { function reset() {
sources_notes_display.length = 0; sources_notes_display.length = 0;
sources.length = 0; sources.length = 0;
@ -150,6 +163,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
$("#first_name").val(""); $("#first_name").val("");
$("#bank").val(""); $("#bank").val("");
refreshBalance(); refreshBalance();
refreshHistory();
} }
$(document).ready(function() { $(document).ready(function() {
@ -161,9 +175,9 @@ SPDX-License-Identifier: GPL-2.0-or-later
dests_notes_display.length = 0; dests_notes_display.length = 0;
dests_notes_display.push(last); dests_notes_display.push(last);
last[3] = 1; last.quantity = 1;
$.getJSON("/api/user/" + last[2].user + "/", function(user) { $.getJSON("/api/user/" + last.note.user + "/", function(user) {
$("#last_name").val(user.last_name); $("#last_name").val(user.last_name);
$("#first_name").val(user.first_name); $("#first_name").val(user.first_name);
}); });
@ -206,30 +220,25 @@ SPDX-License-Identifier: GPL-2.0-or-later
$.post("/api/note/transaction/transaction/", $.post("/api/note/transaction/transaction/",
{ {
"csrfmiddlewaretoken": CSRF_TOKEN, "csrfmiddlewaretoken": CSRF_TOKEN,
"quantity": dest[3], "quantity": dest.quantity,
"amount": $("#amount").val(), "amount": $("#amount").val(),
"reason": $("#reason").val() + " (Don)", "reason": $("#reason").val(),
"valid": true, "valid": true,
"polymorphic_ctype": {{ polymorphic_ctype }}, "polymorphic_ctype": {{ polymorphic_ctype }},
"resourcetype": "Transaction", "resourcetype": "Transaction",
"type": "gift",
"source": {{ user.note.id }}, "source": {{ user.note.id }},
"destination": dest[1] "destination": dest.id
}, function () { }, function () {
let msgDiv = $("#messages"); addMsg("Le transfert de "
let html = msgDiv.html(); + pretty_money(dest.quantity * $("#amount").val()) + " de votre note "
html += "<div class=\"alert alert-success\">Le transfert de " + " vers la note " + dest.name + " a été fait avec succès !", "success");
+ pretty_money(dest[3] * $("#amount").val()) + " de votre note "
+ " vers la note " + dest[0] + " a été fait avec succès !</div>\n";
msgDiv.html(html);
reset(); reset();
}).fail(function (err) { }).fail(function (err) {
let msgDiv = $("#messages"); addMsg("Le transfert de "
let html = msgDiv.html(); + pretty_money(dest.quantity * $("#amount").val()) + " de votre note "
html += "<div class=\"alert alert-danger\">Le transfert de " + " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
+ pretty_money(dest[3] * $("#amount").val()) + " de votre note "
+ " vers la note " + dest[0] + " a échoué : " + err.responseText + "</div>\n";
msgDiv.html(html);
reset(); reset();
}); });
@ -241,30 +250,25 @@ SPDX-License-Identifier: GPL-2.0-or-later
$.post("/api/note/transaction/transaction/", $.post("/api/note/transaction/transaction/",
{ {
"csrfmiddlewaretoken": CSRF_TOKEN, "csrfmiddlewaretoken": CSRF_TOKEN,
"quantity": source[3] * dest[3], "quantity": source.quantity * dest.quantity,
"amount": $("#amount").val(), "amount": $("#amount").val(),
"reason": $("#reason").val() + " (Transfert)", "reason": $("#reason").val(),
"valid": true, "valid": true,
"polymorphic_ctype": {{ polymorphic_ctype }}, "polymorphic_ctype": {{ polymorphic_ctype }},
"resourcetype": "Transaction", "resourcetype": "Transaction",
"source": source[1], "type": "transfer",
"destination": dest[1] "source": source.id,
"destination": dest.id
}, function () { }, function () {
let msgDiv = $("#messages"); addMsg("Le transfert de "
let html = msgDiv.html(); + pretty_money(source.quantity * dest.quantity * $("#amount").val()) + " de la note " + source.name
html += "<div class=\"alert alert-success\">Le transfert de " + " vers la note " + dest.name + " a été fait avec succès !", "success");
+ pretty_money(source[3] * dest[3] * $("#amount").val()) + " de la note " + source[0]
+ " vers la note " + dest[0] + " a été fait avec succès !</div>\n";
msgDiv.html(html);
reset(); reset();
}).fail(function (err) { }).fail(function (err) {
let msgDiv = $("#messages"); addMsg("Le transfert de "
let html = msgDiv.html(); + pretty_money(source.quantity * dest.quantity * $("#amount").val()) + " de la note " + source.name
html += "<div class=\"alert alert-danger\">Le transfert de " + " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
+ pretty_money(source[3] * dest[3] * $("#amount").val()) + " de la note " + source[0]
+ " vers la note " + dest[0] + " a échoué : " + err.responseText + "</div>\n";
msgDiv.html(html);
reset(); reset();
}); });
@ -272,46 +276,46 @@ SPDX-License-Identifier: GPL-2.0-or-later
}); });
} else if ($("#type_credit").is(':checked') || $("#type_debit").is(':checked')) { } else if ($("#type_credit").is(':checked') || $("#type_debit").is(':checked')) {
let special_note = $("#credit_type").val(); let special_note = $("#credit_type").val();
let user_note = dests_notes_display[0][1]; let user_note = dests_notes_display[0].id;
let source, dest, reason; let given_reason = $("#reason").val();
let source, dest, reason, type;
if ($("#type_credit").is(':checked')) { if ($("#type_credit").is(':checked')) {
source = special_note; source = special_note;
dest = user_note; dest = user_note;
reason = $("#reason").val() + " (Crédit " + $("#credit_type option:selected").text().toLowerCase() + ")"; type = "credit";
reason = "Crédit " + $("#credit_type option:selected").text().toLowerCase();
if (given_reason.length > 0)
reason += " (" + given_reason + ")";
} }
else { else {
source = user_note; source = user_note;
dest = special_note; dest = special_note;
reason = $("#reason").val() + " (Retrait " + $("#credit_type option:selected").text().toLowerCase() + ")"; type = "debit";
reason = "Retrait " + $("#credit_type option:selected").text().toLowerCase();
if (given_reason.length > 0)
reason += " (" + given_reason + ")";
} }
$.post("/api/note/transaction/transaction/", $.post("/api/note/transaction/transaction/",
{ {
"csrfmiddlewaretoken": CSRF_TOKEN, "csrfmiddlewaretoken": CSRF_TOKEN,
"quantity": dest[3], "quantity": 1,
"amount": $("#amount").val(), "amount": $("#amount").val(),
"reason": reason, "reason": reason,
"valid": true, "valid": true,
"polymorphic_ctype": {{ special_polymorphic_ctype }}, "polymorphic_ctype": {{ special_polymorphic_ctype }},
"resourcetype": "SpecialTransaction", "resourcetype": "SpecialTransaction",
"type": type,
"source": source, "source": source,
"destination": dest, "destination": dest,
"last_name": $("#last_name").val(), "last_name": $("#last_name").val(),
"first_name": $("#first_name").val(), "first_name": $("#first_name").val(),
"bank": $("#bank").val() "bank": $("#bank").val()
}, function () { }, function () {
let msgDiv = $("#messages"); addMsg("Le crédit/retrait a bien été effectué !", "success");
let html = msgDiv.html();
html += "<div class=\"alert alert-success\">Le crédit/retrait a bien été effectué !</div>\n";
msgDiv.html(html);
reset(); reset();
}).fail(function (err) { }).fail(function (err) {
let msgDiv = $("#messages"); addMsg("Le crédit/transfert a échoué : " + err.responseText, "danger");
let html = msgDiv.html(); reset();
html += "<div class=\"alert alert-danger\">Le crédit/transfert a échoué : " + err.responseText + "</div>\n";
msgDiv.html(html);
reset();
}); });
} }
}); });