1
0
mirror of https://gitlab.crans.org/bde/nk20 synced 2024-11-26 18:37:12 +00:00

Compare commits

..

No commits in common. "11fbbca2a8d88f392c81d21d6aed9b49651c3c6b" and "963ba05d01574de0491d9eec1b13d8fcf8d2a4d2" have entirely different histories.

8 changed files with 31 additions and 72 deletions

View File

@ -142,10 +142,7 @@ class Profile(models.Model):
indexes = [models.Index(fields=['user'])] indexes = [models.Index(fields=['user'])]
def get_absolute_url(self): def get_absolute_url(self):
return reverse('member:user_detail', args=(self.user_id,)) return reverse('user_detail', args=(self.pk,))
def __str__(self):
return str(self.user)
def send_email_validation_link(self): def send_email_validation_link(self):
subject = "[Note Kfet]" + str(_("Activate your Note Kfet account")) subject = "[Note Kfet]" + str(_("Activate your Note Kfet account"))

View File

@ -237,9 +237,9 @@ class TransactionPolymorphicSerializer(PolymorphicSerializer):
field.set(value) field.set(value)
else: else:
setattr(instance, attr, value) setattr(instance, attr, value)
instance.validate() instance.validate(True)
else: else:
serializer.Meta.model(**attrs).validate() serializer.Meta.model(**attrs).validate(True)
attrs[self.resource_type_field_name] = resource_type attrs[self.resource_type_field_name] = resource_type
return super().validate(attrs) return super().validate(attrs)

View File

@ -57,6 +57,7 @@ class TransactionTemplate(models.Model):
amount = models.PositiveIntegerField( amount = models.PositiveIntegerField(
verbose_name=_('amount'), verbose_name=_('amount'),
help_text=_('in centimes'),
) )
category = models.ForeignKey( category = models.ForeignKey(
TemplateCategory, TemplateCategory,
@ -163,7 +164,7 @@ class Transaction(PolymorphicModel):
models.Index(fields=['destination']), models.Index(fields=['destination']),
] ]
def validate(self): def validate(self, reset=False):
previous_source_balance = self.source.balance previous_source_balance = self.source.balance
previous_dest_balance = self.destination.balance previous_dest_balance = self.destination.balance
@ -187,19 +188,23 @@ class Transaction(PolymorphicModel):
source_balance = self.source.balance source_balance = self.source.balance
dest_balance = self.destination.balance dest_balance = self.destination.balance
if reset:
self.source.balance = previous_source_balance
self.destination.balance = previous_dest_balance
if source_balance > 2147483647 or source_balance < -2147483648\ if source_balance > 2147483647 or source_balance < -2147483648\
or dest_balance > 2147483647 or dest_balance < -2147483648: or dest_balance > 2147483647 or dest_balance < -2147483648:
raise ValidationError(_("The note balances must be between - 21 474 836.47 € and 21 474 836.47 €.")) raise ValidationError(_("The note balances must be between - 21 474 836.47 € and 21 474 836.47 €."))
return source_balance - previous_source_balance, dest_balance - previous_dest_balance
@transaction.atomic @transaction.atomic
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
""" """
When saving, also transfer money between two notes When saving, also transfer money between two notes
""" """
with transaction.atomic(): with transaction.atomic():
diff_source, diff_dest = self.validate() self.source.refresh_from_db()
self.destination.refresh_from_db()
self.validate(False)
if not self.source.is_active or not self.destination.is_active: if not self.source.is_active or not self.destination.is_active:
if 'force_insert' not in kwargs or not kwargs['force_insert']: if 'force_insert' not in kwargs or not kwargs['force_insert']:
@ -224,13 +229,9 @@ class Transaction(PolymorphicModel):
self.log("Saved") self.log("Saved")
# Save notes # Save notes
self.source.refresh_from_db()
self.source.balance += diff_source
self.source._force_save = True self.source._force_save = True
self.source.save() self.source.save()
self.log("Source saved") self.log("Source saved")
self.destination.refresh_from_db()
self.destination.balance += diff_dest
self.destination._force_save = True self.destination._force_save = True
self.destination.save() self.destination.save()
self.log("Destination saved") self.log("Destination saved")

View File

@ -847,6 +847,10 @@ msgstr ""
msgid "A template with this name already exist" msgid "A template with this name already exist"
msgstr "" msgstr ""
#: apps/note/models/transactions.py:60
msgid "in centimes"
msgstr ""
#: apps/note/models/transactions.py:72 #: apps/note/models/transactions.py:72
msgid "display" msgid "display"
msgstr "" msgstr ""

View File

@ -504,7 +504,7 @@ msgstr "adresse email confirmée"
#: apps/member/models.py:111 #: apps/member/models.py:111
msgid "registration valid" msgid "registration valid"
msgstr "inscription valide" msgstr "inscription valid"
#: apps/member/models.py:140 apps/member/models.py:141 #: apps/member/models.py:140 apps/member/models.py:141
msgid "user profile" msgid "user profile"
@ -854,6 +854,10 @@ 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:60
msgid "in centimes"
msgstr "en centimes"
#: apps/note/models/transactions.py:72 #: apps/note/models/transactions.py:72
msgid "display" msgid "display"
msgstr "afficher" msgstr "afficher"
@ -2369,7 +2373,7 @@ msgid ""
"You recently registered on the Note Kfet. Please click on the link below to " "You recently registered on the Note Kfet. Please click on the link below to "
"confirm your registration." "confirm your registration."
msgstr "" msgstr ""
"Vous vous êtes inscrit·e récemment sur la Note Kfet. Merci de cliquer sur le " "Vous vous êtes inscrits récemment sur la Note Kfet. Merci de cliquer sur le "
"lien ci-dessous pour confirmer votre adresse email." "lien ci-dessous pour confirmer votre adresse email."
#: templates/registration/mails/email_validation_email.html:26 #: templates/registration/mails/email_validation_email.html:26

View File

@ -265,10 +265,7 @@ function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_pr
consumers.results.forEach(function (consumer) { consumers.results.forEach(function (consumer) {
let note = consumer.note; let note = consumer.note;
note.email_confirmed = consumer.email_confirmed; note.email_confirmed = consumer.email_confirmed;
if (consumer.hasOwnProperty("membership") && consumer.membership) note.membership = consumer.membership;
note.membership = consumer.membership;
else
note.membership = undefined;
let extra_css = displayStyle(note); let extra_css = displayStyle(note);
aliases_matched_html += li(alias_prefix + '_' + consumer.id, aliases_matched_html += li(alias_prefix + '_' + consumer.id,
consumer.name, consumer.name,

View File

@ -1,9 +1,6 @@
// Copyright (C) 2018-2020 by BDE ENS Paris-Saclay // Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// When a transaction is performed, lock the interface to prevent spam clicks.
var LOCK = false;
/** /**
* Refresh the history table on the consumptions page. * Refresh the history table on the consumptions page.
*/ */
@ -38,11 +35,8 @@ $(document).ready(function() {
note_list_obj.html(""); note_list_obj.html("");
buttons.forEach(function(button) { buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(function() { $("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons,
if (LOCK) "consos_list"));
return;
removeNote(button, "conso_button", buttons,"consos_list");
});
}); });
} }
}); });
@ -58,11 +52,8 @@ $(document).ready(function() {
$("#note_list").html(consos_list_obj.html()); $("#note_list").html(consos_list_obj.html());
consos_list_obj.html(""); consos_list_obj.html("");
buttons.forEach(function(button) { buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(function() { $("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons,
if (LOCK) "note_list"));
return;
removeNote(button, "conso_button", buttons,"note_list");
});
}); });
} }
else { else {
@ -136,11 +127,7 @@ function addConso(dest, amount, type, category_id, category_name, template_id, t
$("#" + list).html(html); $("#" + list).html(html);
buttons.forEach(function(button) { buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(function() { $("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons, list));
if (LOCK)
return;
removeNote(button, "conso_button", buttons, list);
});
}); });
} }
else else
@ -161,7 +148,6 @@ function reset() {
$("#profile_pic_link").attr("href", "#"); $("#profile_pic_link").attr("href", "#");
refreshHistory(); refreshHistory();
refreshBalance(); refreshBalance();
LOCK = false;
} }
@ -169,11 +155,6 @@ function reset() {
* Apply all transactions: all notes in `notes` buy each item in `buttons` * Apply all transactions: all notes in `notes` buy each item in `buttons`
*/ */
function consumeAll() { function consumeAll() {
if (LOCK)
return;
LOCK = true;
let error = false; let error = false;
if (notes_display.length === 0) { if (notes_display.length === 0) {
@ -187,10 +168,8 @@ function consumeAll() {
error = true; error = true;
} }
if (error) { if (error)
LOCK = false;
return; return;
}
notes_display.forEach(function(note_display) { notes_display.forEach(function(note_display) {
buttons.forEach(function(button) { buttons.forEach(function(button) {
@ -239,7 +218,7 @@ function consume(source, source_alias, dest, quantity, amount, reason, type, cat
addMsg("Attention, La transaction depuis la note " + source_alias + " a été réalisée avec " + addMsg("Attention, La transaction depuis la note " + source_alias + " a été réalisée avec " +
"succès, mais la note émettrice " + source_alias + " est en négatif.", "succès, mais la note émettrice " + source_alias + " est en négatif.",
"warning", 30000); "warning", 30000);
if (source.membership && source.membership.date_end < new Date().toISOString()) if (source.note.membership && source.note.membership.date_end < new Date().toISOString())
addMsg("Attention : la note émettrice " + source.name + " n'est plus adhérente.", addMsg("Attention : la note émettrice " + source.name + " n'est plus adhérente.",
"danger", 30000); "danger", 30000);
} }

View File

@ -1,5 +1,3 @@
var LOCK = false;
sources = []; sources = [];
sources_notes_display = []; sources_notes_display = [];
dests = []; dests = [];
@ -44,8 +42,6 @@ function reset(refresh=true) {
refreshBalance(); refreshBalance();
refreshHistory(); refreshHistory();
} }
LOCK = false;
} }
$(document).ready(function() { $(document).ready(function() {
@ -95,9 +91,6 @@ $(document).ready(function() {
let dest = $("#dest_note"); let dest = $("#dest_note");
$("#type_transfer").click(function() { $("#type_transfer").click(function() {
if (LOCK)
return;
$("#source_me_div").removeClass('d-none'); $("#source_me_div").removeClass('d-none');
$("#source_note").removeClass('is-invalid'); $("#source_note").removeClass('is-invalid');
$("#dest_note").removeClass('is-invalid'); $("#dest_note").removeClass('is-invalid');
@ -109,9 +102,6 @@ $(document).ready(function() {
}); });
$("#type_credit").click(function() { $("#type_credit").click(function() {
if (LOCK)
return;
$("#source_me_div").addClass('d-none'); $("#source_me_div").addClass('d-none');
$("#source_note").removeClass('is-invalid'); $("#source_note").removeClass('is-invalid');
$("#dest_note").removeClass('is-invalid'); $("#dest_note").removeClass('is-invalid');
@ -132,9 +122,6 @@ $(document).ready(function() {
}); });
$("#type_debit").click(function() { $("#type_debit").click(function() {
if (LOCK)
return;
$("#source_me_div").addClass('d-none'); $("#source_me_div").addClass('d-none');
$("#source_note").removeClass('is-invalid'); $("#source_note").removeClass('is-invalid');
$("#dest_note").removeClass('is-invalid'); $("#dest_note").removeClass('is-invalid');
@ -178,9 +165,6 @@ $(document).ready(function() {
location.hash = ""; location.hash = "";
$("#source_me").click(function() { $("#source_me").click(function() {
if (LOCK)
return;
// Shortcut to set the current user as the only emitter // Shortcut to set the current user as the only emitter
sources_notes_display.length = 0; sources_notes_display.length = 0;
sources.length = 0; sources.length = 0;
@ -214,11 +198,6 @@ $(document).ready(function() {
}); });
$("#btn_transfer").click(function() { $("#btn_transfer").click(function() {
if (LOCK)
return;
LOCK = true;
let error = false; let error = false;
let amount_field = $("#amount"); let amount_field = $("#amount");
@ -258,10 +237,8 @@ $("#btn_transfer").click(function() {
error = true; error = true;
} }
if (error) { if (error)
LOCK = false;
return; return;
}
let reason = reason_field.val(); let reason = reason_field.val();