From d7c500f5d43d58d54adf7f4d6391718405549b67 Mon Sep 17 00:00:00 2001 From: Janusz Kaczmarek Date: Tue, 22 Oct 2024 11:00:09 +0000 Subject: [PATCH] Bug 38235: Suggestion confirmation letter sent when it should not When processing a new order (creating basket, receiving order, etc.) using a bibliographic record once already linked to an old suggestion (already completed in the past), Koha generates and sends a confirmation letter that should not be sent at all. This is because suggestions in Koha are linked to a biblionumber (and not the order), and so the old suggestion is identified - erroneously - as relevant. Then C4::Suggestions::ModSuggestion sends a letter whenever it receives STATUS as a parameter, paying no attention to whether the status is changed. So, in this case, a suggestion already in the status AVAILABLE is "updated" to the status AVAILABLE and the letter is generated. To solve this problem, it should be enough to check whether STATUS is actually changed. Test plan: ========== 1. As a patron, make a purchase suggestion. As a librarian, accept it and process it, as usual, through the acquisition process. 2. At the patron account, as librarian, check the generated notices (the most recent should be "Suggested purchase available"). 3. Make a new aquisition order for the same bibliographic record ("From an existing record:") and receive it as usual. 4. Go to the account of the patron that made the original suggestion and check the notices. Note the second, irrelevant letter "Suggested purchase available". 5. Apply the patch; restart_all. 6. Repeat p. 3 and 4. Note that no new notice has been generated. Sponsored-by: Ignatianum University in Cracow Signed-off-by: Roman Dolny --- C4/Suggestions.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index ed3a19bcfd..154b2e845c 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -251,12 +251,18 @@ sub ModSuggestion { return unless ( $suggestion and defined( $suggestion->{suggestionid} ) ); my $suggestion_object = Koha::Suggestions->find( $suggestion->{suggestionid} ); + my $previous_suggestion_status; + $previous_suggestion_status = $suggestion_object->STATUS if $suggestion_object; eval { # FIXME Must raise an exception instead $suggestion_object->set($suggestion)->store; }; return 0 if $@; - if ( $suggestion->{STATUS} && $suggestion_object->suggestedby ) { + # now send a notification but only if STATUS has been changed + if ( $suggestion->{STATUS} + && $suggestion->{STATUS} ne $previous_suggestion_status + && $suggestion_object->suggestedby ) + { # fetch the entire updated suggestion so that we can populate the letter my $full_suggestion = GetSuggestion( $suggestion->{suggestionid} ); -- 2.39.5