From a2609228dc1b95e2f3afe4fbb4cad18ca9bc02d7 Mon Sep 17 00:00:00 2001 From: Andrew Isherwood Date: Fri, 23 Oct 2020 15:44:32 +0100 Subject: [PATCH] Bug 23971: (follow-up) Make changes for 26582 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 Signed-off-by: Kyle M Hall Signed-off-by: Jonathan Druart --- Koha/Acquisition/Basket.pm | 10 ++++++++++ t/db_dependent/Acquisition.t | 7 +------ t/db_dependent/Koha/Acquisition/Basket.t | 9 ++++++++- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Koha/Acquisition/Basket.pm b/Koha/Acquisition/Basket.pm index 35255bee4b..b2e038a846 100644 --- a/Koha/Acquisition/Basket.pm +++ b/Koha/Acquisition/Basket.pm @@ -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; } diff --git a/t/db_dependent/Acquisition.t b/t/db_dependent/Acquisition.t index 8237996c0a..d39d70334e 100755 --- a/t/db_dependent/Acquisition.t +++ b/t/db_dependent/Acquisition.t @@ -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); @@ -910,11 +910,6 @@ subtest 'Acquisition logging' => sub { my @create_logs = Koha::ActionLogs->search({ module =>'ACQUISITIONS', action => 'ADD_BASKET', object => $basketno }); 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 }); diff --git a/t/db_dependent/Koha/Acquisition/Basket.t b/t/db_dependent/Koha/Acquisition/Basket.t index c8819457a9..ca25462e13 100755 --- a/t/db_dependent/Koha/Acquisition/Basket.t +++ b/t/db_dependent/Koha/Acquisition/Basket.t @@ -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; }; -- 2.39.5