From fe2af5ac2b7069de4f6701d2cebfd1879f0ecf9a Mon Sep 17 00:00:00 2001
From: Yohann D'ANELLO <yohann.danello@gmail.com>
Date: Sat, 15 Aug 2020 19:10:15 +0200
Subject: [PATCH] Pass resourcetype argument correctly when invalidating a
 transaction

---
 apps/note/tables.py         | 3 ++-
 note_kfet/static/js/base.js | 7 ++-----
 2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/apps/note/tables.py b/apps/note/tables.py
index 9786d63b..9a23cd5d 100644
--- a/apps/note/tables.py
+++ b/apps/note/tables.py
@@ -62,7 +62,8 @@ class HistoryTable(tables.Table):
                 "title": lambda record: (_("Click to invalidate") if record.valid else _("Click to validate"))
                 if PermissionBackend.check_perm(get_current_authenticated_user(),
                                                 "note.change_transaction_invalidity_reason", record) else None,
-                "onclick": lambda record: 'de_validate(' + str(record.id) + ', ' + str(record.valid).lower() + ')'
+                "onclick": lambda record: 'de_validate(' + str(record.id) + ', ' + str(record.valid).lower()
+                                          + ', "' + str(record.__class__.__name__) + '")'
                 if PermissionBackend.check_perm(get_current_authenticated_user(),
                                                 "note.change_transaction_invalidity_reason", record) else None,
                 "onmouseover": lambda record: '$("#invalidity_reason_'
diff --git a/note_kfet/static/js/base.js b/note_kfet/static/js/base.js
index 36e8ec84..347696ea 100644
--- a/note_kfet/static/js/base.js
+++ b/note_kfet/static/js/base.js
@@ -348,7 +348,7 @@ function autoCompleteNote(field_id, note_list_id, notes, notes_display, alias_pr
 
 
 // When a validate button is clicked, we switch the validation status
-function de_validate(id, validated) {
+function de_validate(id, validated, resourcetype) {
     let validate_obj = $("#validate_" + id);
 
     if (validate_obj.data("pending"))
@@ -369,14 +369,11 @@ function de_validate(id, validated) {
             "X-CSRFTOKEN": CSRF_TOKEN
         },
         data: {
-            "resourcetype": "RecurrentTransaction",
+            "resourcetype": resourcetype,
             "valid": !validated,
             "invalidity_reason": invalidity_reason,
         },
         success: function () {
-            // Refresh jQuery objects
-            $(".validate").click(de_validate);
-
             refreshBalance();
             // error if this method doesn't exist. Please define it.
             refreshHistory();
-- 
GitLab