diff --git a/apps/treasury/signals.py b/apps/treasury/signals.py
index 54c19c09..188be1a7 100644
--- a/apps/treasury/signals.py
+++ b/apps/treasury/signals.py
@@ -1,6 +1,7 @@
# Copyright (C) 2018-2020 by BDE ENS Paris-Saclay
# SPDX-License-Identifier: GPL-3.0-or-later
+from note.models import NoteSpecial
from treasury.models import SpecialTransactionProxy, RemittanceType
@@ -8,5 +9,6 @@ def save_special_transaction(instance, created, **kwargs):
"""
When a special transaction is created, we create its linked proxy
"""
- if created and RemittanceType.objects.filter(note=instance.source).exists():
+ if created and isinstance(instance.source, NoteSpecial) \
+ and RemittanceType.objects.filter(note=instance.source).exists():
SpecialTransactionProxy.objects.create(transaction=instance, remittance=None).save()
diff --git a/static/js/base.js b/static/js/base.js
index 56c23c85..db12dae9 100644
--- a/static/js/base.js
+++ b/static/js/base.js
@@ -86,7 +86,7 @@ function getMatchedNotes(pattern, fun) {
* Generate a
entry with a given id and text
*/
function li(id, text, extra_css) {
- return "
" + text + "
\n";
}
@@ -126,7 +126,7 @@ function displayNote(note, alias, user_note_field = null, profile_pic_field = nu
if (user_note_field !== null) {
$("#" + user_note_field).removeAttr('class');
$("#" + user_note_field).addClass(displayStyle(note));
- $("#" + user_note_field).text(alias + (note.balance == null ? "" : (":\n" + pretty_money(note.balance))));
+ $("#" + user_note_field).text(alias + (note.balance == null ? "" : (" :\n" + pretty_money(note.balance))));
if (profile_pic_field != null) {
$("#" + profile_pic_field).attr('src', img);
$("#" + profile_pic_field).click(function () {
@@ -162,7 +162,8 @@ function removeNote(d, note_prefix = "note", notes_display, note_list_id, user_n
disp.quantity -= disp.id === d.id ? 1 : 0;
new_notes_display.push(disp);
html += li(note_prefix + "_" + disp.id, disp.name
- + "" + disp.quantity + "");
+ + "" + disp.quantity + "",
+ displayStyle(disp.note));
}
});
@@ -186,7 +187,6 @@ function removeNote(d, note_prefix = "note", notes_display, note_list_id, user_n
/**
* Generate an auto-complete field to query a note with its alias
* @param field_id The identifier of the text field where the alias is typed
- * @param alias_matched_id The div block identifier where the matched aliases are displayed
* @param note_list_id The div block identifier where the notes of the buyers are displayed
* @param notes An array containing the note objects of the buyers
* @param notes_display An array containing the infos of the buyers: [alias, note id, note object, quantity]
@@ -200,11 +200,22 @@ function removeNote(d, note_prefix = "note", notes_display, note_list_id, user_n
* the associated note is not displayed.
* Useful for a consumption if the item is selected before.
*/
-function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes_display, alias_prefix = "alias",
+function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_prefix = "alias",
note_prefix = "note", user_note_field = null, profile_pic_field = null, alias_click = null) {
let field = $("#" + field_id);
- // When the user clicks on the search field, it is immediately cleared
+
+ // Configure tooltip
+ field.tooltip({
+ html: true,
+ placement: 'bottom',
+ title: 'Loading...',
+ trigger: 'manual',
+ container: field.parent()
+ });
+
+ // Clear search on click
field.click(function () {
+ field.tooltip('hide');
field.val("");
});
@@ -213,7 +224,7 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
// When the user type "Enter", the first alias is clicked
field.keypress(function (event) {
if (event.originalEvent.charCode === 13 && notes.length > 0) {
- let li_obj = $("#" + alias_matched_id + " li").first();
+ let li_obj = field.parent().find("ul li").first();
displayNote(notes[0], li_obj.text(), user_note_field, profile_pic_field);
li_obj.trigger("click");
}
@@ -225,19 +236,16 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
return;
let pattern = field.val();
+
// If the pattern is not modified, we don't query the API
if (pattern === old_pattern)
return;
old_pattern = pattern;
notes.length = 0;
- let aliases_matched_obj = $("#" + alias_matched_id);
- let aliases_matched_html = "";
// get matched Alias with note associated
if (pattern === "") {
- aliases_matched_obj = $("#" + alias_matched_id);
- aliases_matched_html = "";
- aliases_matched_obj.html("")
+ field.tooltip('hide');
notes.length = 0;
return;
}
@@ -249,6 +257,9 @@ function autoCompleteNote(field_id, alias_matched_id, note_list_id, notes, notes
// The response arrived too late, we stop the request
if (pattern !== $("#" + field_id).val())
return;
+
+ // Build tooltip content
+ let aliases_matched_html = '