From d9cf812074d840badd1e19a512be81b169e9523b Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Thu, 6 Aug 2020 12:46:44 +0200 Subject: [PATCH] :bug: Prevent transactions to have the same source and destination --- apps/note/models/transactions.py | 3 +-- static/js/transfer.js | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/note/models/transactions.py b/apps/note/models/transactions.py index 6a5d4680..677e0fa8 100644 --- a/apps/note/models/transactions.py +++ b/apps/note/models/transactions.py @@ -222,8 +222,7 @@ class Transaction(PolymorphicModel): self.destination_alias = str(self.destination) if self.source.pk == self.destination.pk: - # When source == destination, no money is transferred - super().save(*args, **kwargs) + # When source == destination, no money is transferred and no transaction is created return self.log("Saving") diff --git a/static/js/transfer.js b/static/js/transfer.js index db467a31..2ee879dc 100644 --- a/static/js/transfer.js +++ b/static/js/transfer.js @@ -246,6 +246,13 @@ $("#btn_transfer").click(function() { // We copy the arrays to ensure that transactions are well-processed even if the form is reset [...sources_notes_display].forEach(function (source) { [...dests_notes_display].forEach(function (dest) { + if (source.note.id === dest.note.id) { + addMsg("Attention : la transaction de " + pretty_money(amount) + " de la note " + source.name + + " vers la note " + dest.name + " n'a pas été faite car il s'agit de la même note au départ" + + " et à l'arrivée.","warning", 10000); + return; + } + $.post("/api/note/transaction/transaction/", { "csrfmiddlewaretoken": CSRF_TOKEN,