From ed795a1d0f11cfdc0d8053cf2f53155adcbb5ff2 Mon Sep 17 00:00:00 2001
From: Katrin Fischer <katrin.fischer@bsz-bw.de>
Date: Tue, 20 Sep 2022 12:47:15 +0000
Subject: [PATCH] Bug 31586: Log basket number as object for action ACQUISITION
 ORDER

Until now we logged undef as object in action_logs when an email
order was sent. With this patch the basket number is logged instead,
which will allow for reporting and also allows us to display a link
to the basket, if permissions permit (order manage), in the log
viewer.

To test:
- Make sure the ClaimsLog system preference is set to Log
- Create a vendor or make sure an existing vendor has an email set
- Make sure to add an SMTP server and link it to your library
- Create a basket in acqisitions and add an order line
- Click "E-mail order" to send the email
- Go to the log viewer, limit to module Acquisitions
- Verify that the entry show with a link to the basket in the
  Object column
  If the user doesn't have order_manage permission, the basket
  number will still show, but isn't linked
---
 C4/Letters.pm                                            | 3 ++-
 koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt | 6 ++++++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/C4/Letters.pm b/C4/Letters.pm
index bde0d2b0dc..781ad8372d 100644
--- a/C4/Letters.pm
+++ b/C4/Letters.pm
@@ -516,11 +516,12 @@ sub SendAlerts {
         return { error => $error }
             unless $success;
 
+        my $log_object = $action eq 'ACQUISITION ORDER' ? $externalid : undef;
         my $module = $action eq 'ACQUISITION ORDER' ? 'ACQUISITIONS' : 'CLAIMS';
         logaction(
             $module,
             $action,
-            undef,
+            $log_object,
             "To="
                 . join( ',', @email )
                 . " Title="
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt
index 24fc22f669..d2c427d84c 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/viewlog.tt
@@ -376,6 +376,12 @@
                                             [% ELSE %]
                                                 Biblio-level recall on <a href="/cgi-bin/koha/catalogue/detail.pl?biblionumber=[% loopro.recall.biblio_id | uri %]">biblio</a>
                                             [% END %]
+                                        [% ELSIF ( loopro.module == 'ACQUISITIONS' && loopro.action == 'ACQUISITION ORDER' && loopro.object ) %]
+                                            [% IF ( CAN_user_acquisition_order_manage ) %]
+                                                Basket <a href="/cgi-bin/koha/acqui/basket.pl?basketno=[% loopro.object | uri %]">[% loopro.object | html %]</a>
+                                            [% ELSE %]
+                                                Basket [% loopro.object | html %]
+                                            [% END %]
                                         [% ELSE %]
                                             [% loopro.object | html %]
                                         [% END %]
-- 
2.30.2