Bugzilla – Attachment 147055 Details for
Bug 33025
Show an alert when adding a lost item to an item bundle
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 33025: Show an alert when adding a lost item to an item bundle
Bug-33025-Show-an-alert-when-adding-a-lost-item-to.patch (text/plain), 7.16 KB, created by
Julian Maurice
on 2023-02-21 15:21:29 UTC
(
hide
)
Description:
Bug 33025: Show an alert when adding a lost item to an item bundle
Filename:
MIME Type:
Creator:
Julian Maurice
Created:
2023-02-21 15:21:29 UTC
Size:
7.16 KB
patch
obsolete
>From 63edcff9e51ca5975bda0af21514db991b2f82df Mon Sep 17 00:00:00 2001 >From: Julian Maurice <julian.maurice@biblibre.com> >Date: Tue, 21 Feb 2023 16:18:02 +0100 >Subject: [PATCH] Bug 33025: Show an alert when adding a lost item to an item > bundle > >Test plan: >1. Create an item bundle (see bug 28854 comment 458) >2. Create a biblio with one item and mark it as lost >3. Try to add the lost item to the bundle > You should see a message saying that the item is lost. Next to > this message should be a button "Mark as found and add to bundle". >4. Click on the button. There should be a message saying that the item > was added to the bundle. >5. Close the modal window and verify that the item was correctly marked > as found and added to the bundle >--- > Koha/Exceptions/Item/Bundle.pm | 4 ++++ > Koha/Item.pm | 8 ++++++++ > Koha/REST/V1/Items.pm | 18 ++++++++++++++++-- > api/v1/swagger/definitions/bundle_link.yaml | 4 ++++ > .../prog/en/modules/catalogue/detail.tt | 12 ++++++++++++ > t/db_dependent/Koha/Item.t | 14 +++++++++++++- > 6 files changed, 57 insertions(+), 3 deletions(-) > >diff --git a/Koha/Exceptions/Item/Bundle.pm b/Koha/Exceptions/Item/Bundle.pm >index 8c42fd2cb2..0f4b00c7cd 100644 >--- a/Koha/Exceptions/Item/Bundle.pm >+++ b/Koha/Exceptions/Item/Bundle.pm >@@ -31,6 +31,10 @@ use Exception::Class ( > isa => 'Koha::Exceptions::Item::Bundle', > description => 'Someone tried to add a checked out item to a bundle', > }, >+ 'Koha::Exceptions::Item::Bundle::ItemIsLost' => { >+ isa => 'Koha::Exceptions::Item::Bundle', >+ description => 'Someone tried to add a lost item to a bundle', >+ }, > ); > > =head1 NAME >diff --git a/Koha/Item.pm b/Koha/Item.pm >index d27b9a2360..f654d7bf2d 100644 >--- a/Koha/Item.pm >+++ b/Koha/Item.pm >@@ -1734,6 +1734,14 @@ sub add_to_bundle { > } > } > >+ if ($bundle_item->itemlost > 0) { >+ unless ($options->{mark_lost_item_as_found}) { >+ Koha::Exceptions::Item::Bundle::ItemIsLost->throw(); >+ } >+ >+ $bundle_item->itemlost(0); >+ } >+ > $self->_result->add_to_item_bundles_hosts( > { item => $bundle_item->itemnumber } ); > >diff --git a/Koha/REST/V1/Items.pm b/Koha/REST/V1/Items.pm >index 365d5e2992..5e8cd6e432 100644 >--- a/Koha/REST/V1/Items.pm >+++ b/Koha/REST/V1/Items.pm >@@ -277,8 +277,13 @@ sub add_to_bundle { > } > > return try { >- my $force_checkin = $c->validation->param('body')->{'force_checkin'}; >- my $link = $item->add_to_bundle($bundle_item, { force_checkin => $force_checkin }); >+ my $body = $c->validation->param('body'); >+ my $options = { >+ force_checkin => $body->{force_checkin}, >+ mark_lost_item_as_found => $body->{mark_lost_item_as_found}, >+ }; >+ >+ my $link = $item->add_to_bundle($bundle_item, $options); > return $c->render( > status => 201, > openapi => $bundle_item >@@ -314,6 +319,15 @@ sub add_to_bundle { > } > ); > } >+ elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::ItemIsLost' ) { >+ return $c->render( >+ status => 409, >+ openapi => { >+ error => 'Item is lost', >+ error_code => 'lost' >+ } >+ ); >+ } > elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) { > return $c->render( > status => 400, >diff --git a/api/v1/swagger/definitions/bundle_link.yaml b/api/v1/swagger/definitions/bundle_link.yaml >index 382ad67516..8af0b053a4 100644 >--- a/api/v1/swagger/definitions/bundle_link.yaml >+++ b/api/v1/swagger/definitions/bundle_link.yaml >@@ -15,4 +15,8 @@ properties: > type: > - boolean > - "null" >+ mark_lost_item_as_found: >+ type: >+ - boolean >+ - "null" > additionalProperties: false >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >index c2dc1b9ca9..67560f0436 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt >@@ -1803,6 +1803,18 @@ Note that permanent location is a code, and location may be an authval. > .empty() > .attr('class', 'alert alert-danger') > .append(__x('Failure: Item {barcode} cannot be checked in', { barcode })) >+ } else if (response.error_code === 'lost') { >+ const button = $('<button type="button">') >+ .addClass('btn btn-xs') >+ .text(__('Mark as found and add to bundle')) >+ .on('click', function () { >+ addToBundle(url, { external_id: barcode, mark_lost_item_as_found: true }); >+ }); >+ $('#addResult') >+ .empty() >+ .attr('class', 'alert alert-warning') >+ .append(__x('Warning: Item {barcode} is marked as lost', { barcode })) >+ .append(' ', button); > } else { > $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>'); > } >diff --git a/t/db_dependent/Koha/Item.t b/t/db_dependent/Koha/Item.t >index db80fd3faf..05d0a593b7 100755 >--- a/t/db_dependent/Koha/Item.t >+++ b/t/db_dependent/Koha/Item.t >@@ -213,7 +213,7 @@ subtest 'bundle_host tests' => sub { > }; > > subtest 'add_to_bundle tests' => sub { >- plan tests => 7; >+ plan tests => 13; > > $schema->storage->txn_begin; > >@@ -227,6 +227,7 @@ subtest 'add_to_bundle tests' => sub { > my $host_item = $builder->build_sample_item(); > my $bundle_item1 = $builder->build_sample_item(); > my $bundle_item2 = $builder->build_sample_item(); >+ my $bundle_item3 = $builder->build_sample_item(); > > throws_ok { $host_item->add_to_bundle($host_item) } > 'Koha::Exceptions::Item::Bundle::IsBundle', >@@ -267,6 +268,17 @@ subtest 'add_to_bundle tests' => sub { > $bundle_item2->discard_changes; > ok( !$bundle_item2->checkout, 'Item is not checked out after being added to a bundle' ); > >+ $bundle_item3->itemlost(1)->store; >+ throws_ok { $host_item->add_to_bundle($bundle_item3) } >+ 'Koha::Exceptions::Item::Bundle::ItemIsLost', >+ 'Exception thrown if you try to add a lost item to a bundle'; >+ >+ lives_ok { $host_item->add_to_bundle($bundle_item3, { mark_lost_item_as_found => 1 }) } >+ 'No exception thrown if you try to add a lost item to a bundle using "mark_lost_item_as_found"'; >+ >+ $bundle_item3->discard_changes; >+ is($bundle_item3->itemlost, 0, 'Item is marked as found after being added to a bundle'); >+ > $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 33025
: 147055