Bug 33021: Show an alert when adding a reserved item to an item bundle
authorJulian Maurice <julian.maurice@biblibre.com>
Tue, 21 Feb 2023 10:14:06 +0000 (11:14 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Mon, 27 Mar 2023 10:50:05 +0000 (12:50 +0200)
Test plan:
1. Create an item bundle (see bug 28854 comment 458)
2. Create a biblio with one item and place a hold for this item.
3. Try to add the reserved item to the bundle
   You should see a message saying that the item is reserved. Next to
   this message should be a button "Ignore holds 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
   added to the bundle

Signed-off-by: Lucas Gass <lucas@bywatersolutiosn.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Koha/Exceptions/Item/Bundle.pm
Koha/Item.pm
Koha/REST/V1/Items.pm
api/v1/swagger/definitions/bundle_link.yaml
koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/detail.tt

index 8c42fd2..fb8c46d 100644 (file)
@@ -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::ItemHasHolds' => {
+        isa         => 'Koha::Exceptions::Item::Bundle',
+        description => 'Someone tried to add a reserved item to a bundle',
+    },
 );
 
 =head1 NAME
index 7e18908..0d29655 100644 (file)
@@ -1730,6 +1730,13 @@ sub add_to_bundle {
                     }
                 }
 
+                my $holds = $bundle_item->current_holds;
+                if ($holds->count) {
+                    unless ($options->{ignore_holds}) {
+                        Koha::Exceptions::Item::Bundle::ItemHasHolds->throw();
+                    }
+                }
+
                 $self->_result->add_to_item_bundles_hosts(
                     { item => $bundle_item->itemnumber } );
 
index 087deb3..3f20e3a 100644 (file)
@@ -278,8 +278,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},
+            ignore_holds => $body->{ignore_holds},
+        };
+
+        my $link = $item->add_to_bundle($bundle_item, $options);
         return $c->render(
             status  => 201,
             openapi => $bundle_item
@@ -315,6 +320,15 @@ sub add_to_bundle {
                 }
             );
         }
+        elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::ItemHasHolds' ) {
+            return $c->render(
+                status  => 409,
+                openapi => {
+                    error      => 'Item is reserved',
+                    error_code => 'reserved'
+                }
+            );
+        }
         elsif ( ref($_) eq 'Koha::Exceptions::Item::Bundle::IsBundle' ) {
             return $c->render(
                 status  => 400,
index 382ad67..b564d03 100644 (file)
@@ -15,4 +15,8 @@ properties:
     type:
       - boolean
       - "null"
+  ignore_holds:
+    type:
+      - boolean
+      - "null"
 additionalProperties: false
index aeda09d..4be5eef 100644 (file)
@@ -1976,6 +1976,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 === 'reserved') {
+                              const button = $('<button type="button">')
+                                .addClass('btn btn-xs')
+                                .text(__('Ignore holds and add to bundle'))
+                                .on('click', function () {
+                                    addToBundle(url, { external_id: barcode, ignore_holds: true });
+                                });
+                              $('#addResult')
+                                .empty()
+                                .attr('class', 'alert alert-warning')
+                                .append(__x('Warning: Item {barcode} is reserved', { barcode }))
+                                .append(' ', button);
                           } else {
                               $('#addResult').replaceWith('<div id="addResult" class="alert alert-danger">'+_("Failure: Item '%s' belongs to another bundle").format(barcode)+'</div>');
                           }