Bug 23971: (follow-up) Make changes for 26582
authorAndrew Isherwood <andrew.isherwood@ptfs-europe.com>
Fri, 23 Oct 2020 14:44:32 +0000 (15:44 +0100)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 23 Apr 2021 09:58:49 +0000 (11:58 +0200)
This commit makes changes necessary to allow this bug to be dependent on
Bug 23562:

- Move basket closure logging from C4::Acquisision::CloseBasket to Koha::Acquisition::Basket::close
- Move basket closure unit test from t/db_dependent/Acquisition.t to
t/db_dependent/Koha/Acquisition/Basket.t

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/Acquisition/Basket.pm
t/db_dependent/Acquisition.t
t/db_dependent/Koha/Acquisition/Basket.t

index 35255be..b2e038a 100644 (file)
@@ -25,6 +25,7 @@ use Koha::Acquisition::BasketGroups;
 use Koha::Acquisition::Orders;
 use Koha::Exceptions::Acquisition::Basket;
 use Koha::Patrons;
+use C4::Log qw(logaction);
 
 use base qw( Koha::Object Koha::Object::Mixin::AdditionalFields );
 
@@ -201,6 +202,15 @@ sub close {
         }
     );
 
+    # Log the closure
+    if (C4::Context->preference("AcqLog")) {
+        logaction(
+            'ACQUISITIONS',
+            'CLOSE_BASKET',
+            $self->id
+        );
+    }
+
     return $self;
 }
 
index 8237996..d39d703 100755 (executable)
@@ -901,7 +901,7 @@ subtest 'GetHistory - is_standing' => sub {
 
 subtest 'Acquisition logging' => sub {
 
-    plan tests => 6;
+    plan tests => 5;
 
     t::lib::Mocks::mock_preference('AcqLog', 1);
 
@@ -911,11 +911,6 @@ subtest 'Acquisition logging' => sub {
     is (scalar @create_logs, 1, 'Basket creation is logged');
 
     Koha::ActionLogs->delete;
-    C4::Acquisition::CloseBasket($basketno);
-    my @close_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'CLOSE_BASKET', object => $basketno });
-    is (scalar @close_logs, 1, 'Basket closure is logged');
-
-    Koha::ActionLogs->delete;
     C4::Acquisition::ReopenBasket($basketno);
     my @reopen_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'REOPEN_BASKET', object => $basketno });
     is (scalar @reopen_logs, 1, 'Basket reopen is logged');
index c881945..ca25462 100755 (executable)
@@ -335,7 +335,11 @@ subtest 'is_closed() tests' => sub {
 
 subtest 'close() tests' => sub {
 
-    plan tests => 3;
+    plan tests => 4;
+
+    # Turn on acquisitions logging and ensure the logs are empty
+    t::lib::Mocks::mock_preference('AcqLog', 1);
+    Koha::ActionLogs->delete;
 
     $schema->storage->txn_begin;
 
@@ -372,5 +376,8 @@ subtest 'close() tests' => sub {
         'Koha::Exceptions::Acquisition::Basket::AlreadyClosed',
         'Trying to close an already closed basket throws an exception';
 
+    my @close_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'CLOSE_BASKET', object => $basket->id });
+    is (scalar @close_logs, 1, 'Basket closure is logged');
+
     $schema->storage->txn_rollback;
 };