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'),
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(
verbose_name=_('reason'),
max_length=255,
@ -158,10 +175,6 @@ class Transaction(PolymorphicModel):
def total(self):
return self.amount * self.quantity
@property
def type(self):
return _('transfer')
class TemplateTransaction(Transaction):
"""
@ -178,10 +191,6 @@ class TemplateTransaction(Transaction):
on_delete=models.PROTECT,
)
@property
def type(self):
return _('template')
class SpecialTransaction(Transaction):
"""
@ -200,7 +209,8 @@ class SpecialTransaction(Transaction):
bank = models.CharField(
max_length=255,
verbose_name=_("bank")
verbose_name=_("bank"),
blank=True,
)
@ -219,7 +229,3 @@ class MembershipTransaction(Transaction):
class Meta:
verbose_name = _("membership transaction")
verbose_name_plural = _("membership transactions")
@property
def type(self):
return _('membership')

View File

@ -6,6 +6,7 @@ import html
import django_tables2 as tables
from django.db.models import F
from django_tables2.utils import A
from django.utils.translation import gettext_lazy as _
from .models.notes import Alias
from .models.transactions import Transaction
@ -21,9 +22,11 @@ class HistoryTable(tables.Table):
model = Transaction
exclude = ("id", "polymorphic_ctype", )
template_name = 'django_tables2/bootstrap4.html'
sequence = ('...', '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),
@ -43,6 +46,9 @@ class HistoryTable(tables.Table):
def render_total(self, value):
return pretty_money(value)
def render_type(self, value):
return _(value)
# Django-tables escape strings. That's a wrong thing.
def render_reason(self, 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.db.models import Q
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 .forms import TransactionTemplateForm
@ -15,14 +15,19 @@ from .models.transactions import SpecialTransaction
from .tables import HistoryTable
class TransactionCreate(LoginRequiredMixin, TemplateView):
class TransactionCreate(LoginRequiredMixin, SingleTableView):
"""
Show transfer page
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"
# Transaction history table
table_class = HistoryTable
table_pagination = {"per_page": 50}
def get_context_data(self, **kwargs):
"""
Add some context variables in template such as page title

View File

@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@ -25,7 +25,7 @@ msgstr ""
#: apps/activity/models.py:19 apps/activity/models.py:44
#: 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/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
msgid "name"
msgstr ""
@ -51,7 +51,7 @@ msgid "description"
msgstr ""
#: 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"
msgstr ""
@ -254,12 +254,12 @@ msgstr ""
msgid "Alias successfully deleted"
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"
msgstr ""
#: 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"
msgstr ""
@ -309,7 +309,7 @@ msgstr ""
msgid "display image"
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"
msgstr ""
@ -395,7 +395,7 @@ msgstr ""
msgid "A template with this name already exist"
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"
msgstr ""
@ -403,47 +403,69 @@ msgstr ""
msgid "in centimes"
msgstr ""
#: apps/note/models/transactions.py:74
#: apps/note/models/transactions.py:75
msgid "transaction template"
msgstr ""
#: apps/note/models/transactions.py:75
#: apps/note/models/transactions.py:76
msgid "transaction templates"
msgstr ""
#: apps/note/models/transactions.py:106
#: apps/note/models/transactions.py:107
msgid "quantity"
msgstr ""
#: apps/note/models/transactions.py:111
msgid "reason"
#: apps/note/models/transactions.py:117 templates/note/transaction_form.html:15
msgid "Gift"
msgstr ""
#: apps/note/models/transactions.py:115
msgid "valid"
#: apps/note/models/transactions.py:118 templates/base.html:90
#: templates/note/transaction_form.html:19
#: templates/note/transaction_form.html:126
msgid "Transfer"
msgstr ""
#: apps/note/models/transactions.py:120
msgid "transaction"
#: apps/note/models/transactions.py:119
msgid "Template"
msgstr ""
#: apps/note/models/transactions.py:121
msgid "transactions"
#: apps/note/models/transactions.py:120 templates/note/transaction_form.html:23
msgid "Credit"
msgstr ""
#: apps/note/models/transactions.py:189
msgid "first_name"
#: apps/note/models/transactions.py:121 templates/note/transaction_form.html:27
msgid "Debit"
msgstr ""
#: apps/note/models/transactions.py:194
msgid "bank"
msgstr ""
#: apps/note/models/transactions.py:211
#: apps/note/models/transactions.py:122 apps/note/models/transactions.py:230
msgid "membership transaction"
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
msgid "bank"
msgstr ""
#: apps/note/models/transactions.py:231
msgid "membership transactions"
msgstr ""
@ -451,7 +473,7 @@ msgstr ""
msgid "Transfer money"
msgstr ""
#: apps/note/views.py:129 templates/base.html:71
#: apps/note/views.py:132 templates/base.html:78
msgid "Consumptions"
msgstr ""
@ -478,23 +500,18 @@ msgstr ""
msgid "The ENS Paris-Saclay BDE note."
msgstr ""
#: templates/base.html:74
#: templates/base.html:81
msgid "Clubs"
msgstr ""
#: templates/base.html:77
#: templates/base.html:84
msgid "Activities"
msgstr ""
#: templates/base.html:80
#: templates/base.html:87
msgid "Buttons"
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
msgid "Central Authentication Service"
msgstr ""
@ -644,42 +661,30 @@ msgstr ""
msgid "Select consumptions"
msgstr ""
#: templates/note/conso_form.html:50
#: templates/note/conso_form.html:51
msgid "Consume!"
msgstr ""
#: templates/note/conso_form.html:62
msgid "The most used buttons will display here."
#: templates/note/conso_form.html:64
msgid "Most used buttons"
msgstr ""
#: templates/note/conso_form.html:107
#: templates/note/conso_form.html:121
msgid "Edit"
msgstr ""
#: templates/note/conso_form.html:112
#: templates/note/conso_form.html:126
msgid "Single consumptions"
msgstr ""
#: templates/note/conso_form.html:116
#: templates/note/conso_form.html:130
msgid "Double consumptions"
msgstr ""
#: templates/note/conso_form.html:127
#: templates/note/conso_form.html:141
msgid "Recent transactions history"
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
msgid "External payment"
msgstr ""

View File

@ -3,7 +3,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\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"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\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/member/models.py:61 apps/member/models.py:112
#: 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
msgid "name"
msgstr "nom"
@ -46,7 +46,7 @@ msgid "description"
msgstr "description"
#: 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"
msgstr "type"
@ -253,12 +253,12 @@ msgstr "Compte n°%(id)s : %(username)s"
msgid "Alias successfully deleted"
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"
msgstr "source"
#: 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"
msgstr "destination"
@ -309,7 +309,7 @@ msgstr ""
msgid "display image"
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"
msgstr "créée le"
@ -395,7 +395,7 @@ msgstr "catégories de transaction"
msgid "A template with this name already exist"
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"
msgstr "montant"
@ -403,47 +403,69 @@ msgstr "montant"
msgid "in centimes"
msgstr "en centimes"
#: apps/note/models/transactions.py:74
#: apps/note/models/transactions.py:75
msgid "transaction template"
msgstr "modèle de transaction"
#: apps/note/models/transactions.py:75
#: apps/note/models/transactions.py:76
msgid "transaction templates"
msgstr "modèles de transaction"
#: apps/note/models/transactions.py:106
#: apps/note/models/transactions.py:107
msgid "quantity"
msgstr "quantité"
#: apps/note/models/transactions.py:111
msgid "reason"
msgstr "raison"
#: apps/note/models/transactions.py:117 templates/note/transaction_form.html:15
msgid "Gift"
msgstr "Don"
#: apps/note/models/transactions.py:115
msgid "valid"
msgstr "valide"
#: apps/note/models/transactions.py:118 templates/base.html:90
#: templates/note/transaction_form.html:19
#: templates/note/transaction_form.html:126
msgid "Transfer"
msgstr "Virement"
#: apps/note/models/transactions.py:120
msgid "transaction"
msgstr "transaction"
#: apps/note/models/transactions.py:119
msgid "Template"
msgstr "Bouton"
#: apps/note/models/transactions.py:121
msgid "transactions"
msgstr "transactions"
#: apps/note/models/transactions.py:120 templates/note/transaction_form.html:23
msgid "Credit"
msgstr "Crédit"
#: apps/note/models/transactions.py:189
msgid "first_name"
msgstr ""
#: apps/note/models/transactions.py:121 templates/note/transaction_form.html:27
msgid "Debit"
msgstr "Retrait"
#: apps/note/models/transactions.py:194
msgid "bank"
msgstr ""
#: apps/note/models/transactions.py:211
#: apps/note/models/transactions.py:122 apps/note/models/transactions.py:230
msgid "membership transaction"
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
msgid "bank"
msgstr "Banque"
#: apps/note/models/transactions.py:231
msgid "membership transactions"
msgstr "transactions d'adhésion"
@ -451,7 +473,7 @@ msgstr "transactions d'adhésion"
msgid "Transfer money"
msgstr "Transferts d'argent"
#: apps/note/views.py:129 templates/base.html:71
#: apps/note/views.py:132 templates/base.html:78
msgid "Consumptions"
msgstr "Consommations"
@ -478,23 +500,18 @@ msgstr ""
msgid "The ENS Paris-Saclay BDE note."
msgstr "La note du BDE de l'ENS Paris-Saclay."
#: templates/base.html:74
#: templates/base.html:81
msgid "Clubs"
msgstr "Clubs"
#: templates/base.html:77
#: templates/base.html:84
msgid "Activities"
msgstr "Activités"
#: templates/base.html:80
#: templates/base.html:87
msgid "Buttons"
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
msgid "Central Authentication Service"
msgstr ""
@ -555,7 +572,7 @@ msgstr ""
#: templates/django_filters/rest_framework/form.html:5
#: templates/member/club_form.html:10
msgid "Submit"
msgstr ""
msgstr "Envoyer"
#: templates/member/club_detail.html:10
msgid "Membership starts on"
@ -646,43 +663,30 @@ msgstr "Sélection des émetteurs"
msgid "Select consumptions"
msgstr "Consommations"
#: templates/note/conso_form.html:50
#: templates/note/conso_form.html:51
msgid "Consume!"
msgstr "Consommer !"
#: templates/note/conso_form.html:62
#: templates/note/conso_form.html:64
msgid "Most used buttons"
msgstr "Boutons les plus utilisés"
#: templates/note/conso_form.html:107
#: templates/note/conso_form.html:121
msgid "Edit"
msgstr "Éditer"
#: templates/note/conso_form.html:112
#| msgid "Consumptions"
#: templates/note/conso_form.html:126
msgid "Single consumptions"
msgstr "Consos simples"
#: templates/note/conso_form.html:116
#: templates/note/conso_form.html:130
msgid "Double consumptions"
msgstr "Consos doubles"
#: templates/note/conso_form.html:127
#: templates/note/conso_form.html:141
msgid "Recent transactions history"
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
msgid "External payment"
msgstr "Paiement extérieur"

View File

@ -15,6 +15,18 @@ function pretty_money(value) {
+ (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
*/
@ -256,11 +268,8 @@ function de_validate(id, validated) {
refreshHistory();
},
error: function(err) {
let msgDiv = $("#messages");
let html = msgDiv.html();
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);
addMsg("Une erreur est survenue lors de la validation/dévalidation " +
"de cette transaction : " + err.responseText, "danger");
refreshBalance();
// 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();
}
/**
* 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`
*/
@ -161,19 +177,14 @@ function consume(source, dest, quantity, amount, reason, type, category, templat
"valid": true,
"polymorphic_ctype": type,
"resourcetype": "TemplateTransaction",
"type": "template",
"source": source,
"destination": dest,
"category": category,
"template": template
}, function() {
notes_display.length = 0;
notes.length = 0;
buttons.length = 0;
$("#note_list").html("");
$("#alias_matched").html("");
$("#consos_list").html("");
displayNote(null, "");
refreshHistory();
refreshBalance();
}, reset).fail(function (e) {
reset();
addMsg("Une erreur est survenue lors de la transaction : " + e.responseText, "danger");
});
}

View File

@ -3,7 +3,7 @@
SPDX-License-Identifier: GPL-2.0-or-later
{% endcomment %}
{% load i18n static %}
{% load i18n static django_tables2 %}
{% 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>
</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 %}
{% block extrajavascript %}
@ -135,6 +144,10 @@ SPDX-License-Identifier: GPL-2.0-or-later
dests = [];
dests_notes_display = [];
function refreshHistory() {
$("#history").load("/note/transfer/ #history");
}
function reset() {
sources_notes_display.length = 0;
sources.length = 0;
@ -150,6 +163,7 @@ SPDX-License-Identifier: GPL-2.0-or-later
$("#first_name").val("");
$("#bank").val("");
refreshBalance();
refreshHistory();
}
$(document).ready(function() {
@ -161,9 +175,9 @@ SPDX-License-Identifier: GPL-2.0-or-later
dests_notes_display.length = 0;
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);
$("#first_name").val(user.first_name);
});
@ -206,30 +220,25 @@ SPDX-License-Identifier: GPL-2.0-or-later
$.post("/api/note/transaction/transaction/",
{
"csrfmiddlewaretoken": CSRF_TOKEN,
"quantity": dest[3],
"quantity": dest.quantity,
"amount": $("#amount").val(),
"reason": $("#reason").val() + " (Don)",
"reason": $("#reason").val(),
"valid": true,
"polymorphic_ctype": {{ polymorphic_ctype }},
"resourcetype": "Transaction",
"type": "gift",
"source": {{ user.note.id }},
"destination": dest[1]
"destination": dest.id
}, function () {
let msgDiv = $("#messages");
let html = msgDiv.html();
html += "<div class=\"alert alert-success\">Le transfert de "
+ 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);
addMsg("Le transfert de "
+ pretty_money(dest.quantity * $("#amount").val()) + " de votre note "
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
reset();
}).fail(function (err) {
let msgDiv = $("#messages");
let html = msgDiv.html();
html += "<div class=\"alert alert-danger\">Le transfert de "
+ pretty_money(dest[3] * $("#amount").val()) + " de votre note "
+ " vers la note " + dest[0] + " a échoué : " + err.responseText + "</div>\n";
msgDiv.html(html);
addMsg("Le transfert de "
+ pretty_money(dest.quantity * $("#amount").val()) + " de votre note "
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
reset();
});
@ -241,30 +250,25 @@ SPDX-License-Identifier: GPL-2.0-or-later
$.post("/api/note/transaction/transaction/",
{
"csrfmiddlewaretoken": CSRF_TOKEN,
"quantity": source[3] * dest[3],
"quantity": source.quantity * dest.quantity,
"amount": $("#amount").val(),
"reason": $("#reason").val() + " (Transfert)",
"reason": $("#reason").val(),
"valid": true,
"polymorphic_ctype": {{ polymorphic_ctype }},
"resourcetype": "Transaction",
"source": source[1],
"destination": dest[1]
"type": "transfer",
"source": source.id,
"destination": dest.id
}, function () {
let msgDiv = $("#messages");
let html = msgDiv.html();
html += "<div class=\"alert alert-success\">Le transfert de "
+ 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);
addMsg("Le transfert de "
+ pretty_money(source.quantity * dest.quantity * $("#amount").val()) + " de la note " + source.name
+ " vers la note " + dest.name + " a été fait avec succès !", "success");
reset();
}).fail(function (err) {
let msgDiv = $("#messages");
let html = msgDiv.html();
html += "<div class=\"alert alert-danger\">Le transfert de "
+ 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);
addMsg("Le transfert de "
+ pretty_money(source.quantity * dest.quantity * $("#amount").val()) + " de la note " + source.name
+ " vers la note " + dest.name + " a échoué : " + err.responseText, "danger");
reset();
});
@ -272,45 +276,45 @@ SPDX-License-Identifier: GPL-2.0-or-later
});
} else if ($("#type_credit").is(':checked') || $("#type_debit").is(':checked')) {
let special_note = $("#credit_type").val();
let user_note = dests_notes_display[0][1];
let source, dest, reason;
let user_note = dests_notes_display[0].id;
let given_reason = $("#reason").val();
let source, dest, reason, type;
if ($("#type_credit").is(':checked')) {
source = special_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 {
source = user_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/",
{
"csrfmiddlewaretoken": CSRF_TOKEN,
"quantity": dest[3],
"quantity": 1,
"amount": $("#amount").val(),
"reason": reason,
"valid": true,
"polymorphic_ctype": {{ special_polymorphic_ctype }},
"resourcetype": "SpecialTransaction",
"type": type,
"source": source,
"destination": dest,
"last_name": $("#last_name").val(),
"first_name": $("#first_name").val(),
"bank": $("#bank").val()
}, function () {
let msgDiv = $("#messages");
let html = msgDiv.html();
html += "<div class=\"alert alert-success\">Le crédit/retrait a bien été effectué !</div>\n";
msgDiv.html(html);
addMsg("Le crédit/retrait a bien été effectué !", "success");
reset();
}).fail(function (err) {
let msgDiv = $("#messages");
let html = msgDiv.html();
html += "<div class=\"alert alert-danger\">Le crédit/transfert a échoué : " + err.responseText + "</div>\n";
msgDiv.html(html);
addMsg("Le crédit/transfert a échoué : " + err.responseText, "danger");
reset();
});
}