Bugzilla – Attachment 159525 Details for
Bug 27595
Place holds for patrons on accepted purchase suggestions
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 27595: Add place_hold method to Koha::Suggestion
Bug-27595-Add-placehold-method-to-KohaSuggestion.patch (text/plain), 3.97 KB, created by
Nick Clemens (kidclamp)
on 2023-12-04 14:13:20 UTC
(
hide
)
Description:
Bug 27595: Add place_hold method to Koha::Suggestion
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2023-12-04 14:13:20 UTC
Size:
3.97 KB
patch
obsolete
>From bdf0e78dcdef1247887c18a32ab5900f36a10a25 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Mon, 4 Dec 2023 14:04:44 +0000 >Subject: [PATCH] Bug 27595: Add place_hold method to Koha::Suggestion > >This patch adds anew method to allow placing a hold from a purchase suggestion > >To test: >prove -v t/db_dependent/Suggestions.t >--- > Koha/Suggestion.pm | 25 +++++++++++++++++++ > t/db_dependent/Suggestions.t | 48 +++++++++++++++++++++++++++++++++++- > 2 files changed, 72 insertions(+), 1 deletion(-) > >diff --git a/Koha/Suggestion.pm b/Koha/Suggestion.pm >index 631c1f662a4..f406b71f0a9 100644 >--- a/Koha/Suggestion.pm >+++ b/Koha/Suggestion.pm >@@ -21,6 +21,7 @@ use Modern::Perl; > > use C4::Context; > use C4::Letters; >+use C4::Reserves qw( AddReserve ); > > use Koha::Database; > use Koha::DateUtils qw( dt_from_string ); >@@ -207,6 +208,30 @@ sub fund { > return Koha::Acquisition::Fund->_new_from_dbic($fund_rs); > } > >+=head3 place_hold >+ >+my $hold_id = $suggestion->place_hold(); >+ >+Places a hold for the suggester if the suggestion is tied to a biblio. >+ >+=cut >+ >+sub place_hold { >+ my ($self) = @_; >+ >+ return unless C4::Context->preference('PlaceHoldsOnOrdersFromSuggestions'); >+ return unless $self->biblionumber; >+ >+ my $hold_id = AddReserve( >+ { >+ borrowernumber => $self->suggestedby, >+ biblionumber => $self->biblionumber, >+ branchcode => $self->branchcode, >+ title => $self->title, >+ } >+ ); >+} >+ > =head3 type > > =cut >diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t >index abcbd626c50..88aae138c17 100755 >--- a/t/db_dependent/Suggestions.t >+++ b/t/db_dependent/Suggestions.t >@@ -18,7 +18,7 @@ > use Modern::Perl; > > use DateTime::Duration; >-use Test::More tests => 91; >+use Test::More tests => 92; > use Test::Warn; > > use t::lib::Mocks; >@@ -29,6 +29,7 @@ use C4::Letters qw( GetQueuedMessages GetMessage ); > use C4::Budgets qw( AddBudgetPeriod AddBudget GetBudget ); > use Koha::Database; > use Koha::DateUtils qw( dt_from_string output_pref ); >+use Koha::Holds; > use Koha::Libraries; > use Koha::Patrons; > use Koha::Suggestions; >@@ -594,6 +595,51 @@ subtest 'ModSuggestion should work on suggestions without a suggester' => sub { > is( $suggestion->{note}, "Test note", "ModSuggestion works on suggestions without a suggester" ); > }; > >+subtest 'place_hold tests' => sub { >+ plan tests => 4; >+ >+ t::lib::Mocks::mock_preference( "PlaceHoldsOnOrdersFromSuggestions", "0" ); >+ >+ my $biblio = $builder->build_sample_biblio(); >+ my $patron = $builder->build_object( { class => 'Koha::Patrons' } ); >+ my $suggestion = $builder->build_object( >+ { >+ class => 'Koha::Suggestions', >+ value => { >+ branchcode => $patron->branchcode, >+ biblionumber => undef, >+ suggestedby => $patron->id >+ } >+ } >+ ); >+ >+ my $hold_id = $suggestion->place_hold(); >+ is( $hold_id, undef, "No suggestion placed when preference is disabled" ); >+ >+ t::lib::Mocks::mock_preference( "PlaceHoldsOnOrdersFromSuggestions", "1" ); >+ >+ $hold_id = $suggestion->place_hold(); >+ is( >+ $hold_id, undef, >+ "No suggestion placed when preference is enabled and suggestion does not have a biblionumber" >+ ); >+ >+ $suggestion->biblionumber( $biblio->id )->store(); >+ $suggestion->discard_changes(); >+ >+ $hold_id = $suggestion->place_hold(); >+ ok( $hold_id, "Suggestion placed when preference is enabled and suggestion does have a biblionumber" ); >+ >+ my $hold = Koha::Holds->find($hold_id); >+ $hold->delete(); >+ >+ t::lib::Mocks::mock_preference( "PlaceHoldsOnOrdersFromSuggestions", "0" ); >+ >+ $hold_id = $suggestion->place_hold(); >+ is( $hold_id, undef, "Suggestion not placed when preference is disabled and suggestion does have a biblionumber" ); >+ >+}; >+ > subtest 'Suggestion with ISBN' => sub { > my $suggestion_with_isbn = { > isbn => '1940997232', >-- >2.30.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 27595
:
159524
|
159525
|
159526
|
159533
|
159534
|
159535
|
159537
|
159538
|
159539
|
159540
|
159541
|
159542
|
159786
|
159787
|
159788
|
163331
|
163332
|
163333