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'])]
def get_absolute_url(self):
return reverse('member:user_detail', args=(self.user_id,))
def __str__(self):
return str(self.user)
return reverse('user_detail', args=(self.pk,))
def send_email_validation_link(self):
subject = "[Note Kfet]" + str(_("Activate your Note Kfet account"))

View File

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

View File

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

View File

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

View File

@ -504,7 +504,7 @@ msgstr "adresse email confirmée"
#: apps/member/models.py:111
msgid "registration valid"
msgstr "inscription valide"
msgstr "inscription valid"
#: apps/member/models.py:140 apps/member/models.py:141
msgid "user profile"
@ -854,6 +854,10 @@ 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:60
msgid "in centimes"
msgstr "en centimes"
#: apps/note/models/transactions.py:72
msgid "display"
msgstr "afficher"
@ -2369,7 +2373,7 @@ msgid ""
"You recently registered on the Note Kfet. Please click on the link below to "
"confirm your registration."
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."
#: 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) {
let note = consumer.note;
note.email_confirmed = consumer.email_confirmed;
if (consumer.hasOwnProperty("membership") && consumer.membership)
note.membership = consumer.membership;
else
note.membership = undefined;
note.membership = consumer.membership;
let extra_css = displayStyle(note);
aliases_matched_html += li(alias_prefix + '_' + consumer.id,
consumer.name,

View File

@ -1,9 +1,6 @@
// Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
// 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.
*/
@ -38,11 +35,8 @@ $(document).ready(function() {
note_list_obj.html("");
buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(function() {
if (LOCK)
return;
removeNote(button, "conso_button", buttons,"consos_list");
});
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons,
"consos_list"));
});
}
});
@ -58,11 +52,8 @@ $(document).ready(function() {
$("#note_list").html(consos_list_obj.html());
consos_list_obj.html("");
buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(function() {
if (LOCK)
return;
removeNote(button, "conso_button", buttons,"note_list");
});
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons,
"note_list"));
});
}
else {
@ -136,11 +127,7 @@ function addConso(dest, amount, type, category_id, category_name, template_id, t
$("#" + list).html(html);
buttons.forEach(function(button) {
$("#conso_button_" + button.id).click(function() {
if (LOCK)
return;
removeNote(button, "conso_button", buttons, list);
});
$("#conso_button_" + button.id).click(removeNote(button, "conso_button", buttons, list));
});
}
else
@ -161,7 +148,6 @@ function reset() {
$("#profile_pic_link").attr("href", "#");
refreshHistory();
refreshBalance();
LOCK = false;
}
@ -169,11 +155,6 @@ function reset() {
* Apply all transactions: all notes in `notes` buy each item in `buttons`
*/
function consumeAll() {
if (LOCK)
return;
LOCK = true;
let error = false;
if (notes_display.length === 0) {
@ -187,10 +168,8 @@ function consumeAll() {
error = true;
}
if (error) {
LOCK = false;
if (error)
return;
}
notes_display.forEach(function(note_display) {
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 " +
"succès, mais la note émettrice " + source_alias + " est en négatif.",
"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.",
"danger", 30000);
}

View File

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