Bugzilla – Attachment 143627 Details for
Bug 31692
Let librarians change item level holds to record level holds when possible
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 31692: Add Koha::Hold::change_type and unit tests
Bug-31692-Add-KohaHoldchangetype-and-unit-tests.patch (text/plain), 4.34 KB, created by
Katrin Fischer
on 2022-11-10 09:36:03 UTC
(
hide
)
Description:
Bug 31692: Add Koha::Hold::change_type and unit tests
Filename:
MIME Type:
Creator:
Katrin Fischer
Created:
2022-11-10 09:36:03 UTC
Size:
4.34 KB
patch
obsolete
>From 6a2be8d53b4d2c49ef79595b34680ddcd69994bc Mon Sep 17 00:00:00 2001 >From: Lari Taskula <lari.taskula@hypernova.fi> >Date: Wed, 5 Oct 2022 14:54:03 +0000 >Subject: [PATCH] Bug 31692: Add Koha::Hold::change_type and unit tests > >To test: >1. prove t/db_dependent/Koha/Hold.t > >Signed-off-by: David Nind <david@davidnind.com> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> > >Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> >--- > Koha/Exceptions/Hold.pm | 4 +++ > Koha/Hold.pm | 33 ++++++++++++++++++++ > t/db_dependent/Koha/Hold.t | 62 +++++++++++++++++++++++++++++++++++++- > 3 files changed, 98 insertions(+), 1 deletion(-) > >diff --git a/Koha/Exceptions/Hold.pm b/Koha/Exceptions/Hold.pm >index b09dcd65b5..38577b4126 100644 >--- a/Koha/Exceptions/Hold.pm >+++ b/Koha/Exceptions/Hold.pm >@@ -23,6 +23,10 @@ use Exception::Class ( > 'Koha::Exceptions::Hold' => { > isa => 'Koha::Exception', > }, >+ 'Koha::Exceptions::Hold::CannotChangeHoldType' => { >+ isa => 'Koha::Exceptions::Hold', >+ description => "Record cannot have both record and item level holds at the same time", >+ }, > 'Koha::Exceptions::Hold::CannotSuspendFound' => { > isa => 'Koha::Exceptions::Hold', > description => "Found holds cannot be suspended", >diff --git a/Koha/Hold.pm b/Koha/Hold.pm >index a5a9d03003..1d386bdeb6 100644 >--- a/Koha/Hold.pm >+++ b/Koha/Hold.pm >@@ -844,6 +844,39 @@ sub fill { > return $self; > } > >+=head3 sub change_type >+ >+ $hold->change_type # to record level >+ $hold->change_type( $itemnumber ) # to item level >+ >+Changes hold type between record and item level holds, only if record has >+exactly one hold for a patron. This is because Koha expects all holds for >+a patron on a record to be alike. >+ >+=cut >+ >+sub change_type { >+ my ( $self, $itemnumber ) = @_; >+ >+ my $record_holds_per_patron = Koha::Holds->search( { >+ borrowernumber => $self->borrowernumber, >+ biblionumber => $self->biblionumber, >+ } ); >+ >+ if ( $itemnumber && $self->itemnumber ) { >+ $self->itemnumber( $itemnumber )->store; >+ return $self; >+ } >+ >+ if ( $record_holds_per_patron->count == 1 ) { >+ $self->set({ itemnumber => $itemnumber ? $itemnumber : undef })->store; >+ } else { >+ Koha::Exceptions::Hold::CannotChangeHoldType->throw(); >+ } >+ >+ return $self; >+} >+ > =head3 store > > Override base store method to set default >diff --git a/t/db_dependent/Koha/Hold.t b/t/db_dependent/Koha/Hold.t >index 7146541522..0c9a073611 100755 >--- a/t/db_dependent/Koha/Hold.t >+++ b/t/db_dependent/Koha/Hold.t >@@ -19,7 +19,7 @@ > > use Modern::Perl; > >-use Test::More tests => 11; >+use Test::More tests => 12; > > use Test::Exception; > use Test::MockModule; >@@ -955,3 +955,63 @@ subtest 'Koha::Hold::item_group tests' => sub { > > $schema->storage->txn_rollback; > }; >+ >+subtest 'change_type tests' => sub { >+ >+ plan tests => 9; >+ >+ $schema->storage->txn_begin; >+ >+ my $item = $builder->build_object( { class => 'Koha::Items', } ); >+ my $hold = $builder->build_object( { >+ class => 'Koha::Holds', >+ value => { >+ itemnumber => undef, >+ } >+ } ); >+ >+ my $hold2 = $builder->build_object( { >+ class => 'Koha::Holds', >+ value => { >+ borrowernumber => $hold->borrowernumber, >+ } >+ } ); >+ >+ ok( $hold->change_type ); >+ >+ $hold->discard_changes; >+ >+ is( $hold->itemnumber, undef, 'record hold to record hold, no changes'); >+ >+ ok( $hold->change_type( $item->itemnumber ) ); >+ >+ $hold->discard_changes; >+ >+ is( $hold->itemnumber, $item->itemnumber, 'record hold to item hold'); >+ >+ ok( $hold->change_type( $item->itemnumber ) ); >+ >+ $hold->discard_changes; >+ >+ is( $hold->itemnumber, $item->itemnumber, 'item hold to item hold, no changes'); >+ >+ ok( $hold->change_type ); >+ >+ $hold->discard_changes; >+ >+ is( $hold->itemnumber, undef, 'item hold to record hold'); >+ >+ my $hold3 = $builder->build_object( { >+ class => 'Koha::Holds', >+ value => { >+ biblionumber => $hold->biblionumber, >+ borrowernumber => $hold->borrowernumber, >+ } >+ } ); >+ >+ throws_ok { $hold->change_type } >+ 'Koha::Exceptions::Hold::CannotChangeHoldType', >+ 'Exception thrown because more than one hold per record'; >+ >+ $schema->storage->txn_rollback; >+}; >-- >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 31692
:
141388
|
141390
|
142102
|
142103
|
142104
|
142106
|
142107
|
142108
|
142109
|
142114
|
142115
|
142116
|
142117
|
142118
|
142586
|
142587
|
142595
|
142596
|
142818
|
142819
|
143151
|
143160
|
143161
|
143162
|
143614
|
143615
|
143616
|
143617
|
143618
|
143619
| 143627 |
143628
|
143629