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 <roman.dolny@jezuici.pl>
Signed-off-by: Aleisha Amohia <aleishaamohia@hotmail.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Janusz Kaczmarek 2024-10-22 11:00:09 +00:00 committed by Katrin Fischer
parent 0ab32306ee
commit 97ce4ab029
Signed by: kfischer
GPG key ID: 0EF6E2C03357A834

View file

@ -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} );