From 2472214301fc04250a978570b78096ebf4d5e5d1 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 10 Nov 2021 11:42:17 +0000 Subject: [PATCH] Bug 29002: Add bookable state to items This patch adds a bookable boolean to enable/disable the ability to book an item ahead of time Test plan 1) Navigate to the 'Items' tab of a biblio 2) Note the new 'Bookable' option and select at least one item to allow bookings to take place 3) Note that without any items selected as 'bookable' one does not have the 'Place booking' option or the 'Bookings' tab on the biblio details page. 4) Note that when at least one item is bookable, the place booking modal now only displays items that are marked as bookable in the item selection 5) Sign off Signed-off-by: Martin Renvoize Signed-off-by: Janet McGowan Signed-off-by: Caroline Cyr La Rose Signed-off-by: Laurence Rault Signed-off-by: Kyle M Hall Signed-off-by: Tomas Cohen Arazi --- Koha/Items.pm | 9 +++---- Koha/Template/Plugin/Biblio.pm | 7 ++++++ api/v1/swagger/definitions/item.yaml | 3 +++ catalogue/updateitem.pl | 3 +++ .../data/mysql/atomicupdate/bug_29002.pl | 22 ++++++++++++---- installer/data/mysql/kohastructure.sql | 2 ++ .../prog/en/includes/biblio-view-menu.inc | 2 ++ .../prog/en/includes/cat-toolbar.inc | 3 +++ .../prog/en/modules/catalogue/moredetail.tt | 25 +++++++++++++++++++ 9 files changed, 65 insertions(+), 11 deletions(-) diff --git a/Koha/Items.pm b/Koha/Items.pm index 873da63a3e..d95d3f811c 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -169,12 +169,9 @@ Returns a new resultset, containing only those items that are allowed to be book sub filter_by_bookable { my ($self) = @_; - return $self->search( - { - notforloan => [ 0, undef ], - withdrawn => [ 0, undef ] - } - ); + my $params = { bookable => 1 }; + + return $self->search( $params ); } =head3 move_to_biblio diff --git a/Koha/Template/Plugin/Biblio.pm b/Koha/Template/Plugin/Biblio.pm index 92b130ac10..f2163e41b3 100644 --- a/Koha/Template/Plugin/Biblio.pm +++ b/Koha/Template/Plugin/Biblio.pm @@ -65,4 +65,11 @@ sub RecallsCount { return $recalls->count; } +sub CanBook { + my ( $self, $biblionumber ) = @_; + + my $biblio = Koha::Biblios->find( $biblionumber ); + return $biblio->bookable_items->count ? 1 : 0; +} + 1; diff --git a/api/v1/swagger/definitions/item.yaml b/api/v1/swagger/definitions/item.yaml index fc1cc718f4..1d0ed7ac95 100644 --- a/api/v1/swagger/definitions/item.yaml +++ b/api/v1/swagger/definitions/item.yaml @@ -24,6 +24,9 @@ properties: - string - "null" description: Information about the acquisition source (it is not really a vendor id) + bookable: + type: boolean + description: Allow bookings on this item. home_library_id: type: - string diff --git a/catalogue/updateitem.pl b/catalogue/updateitem.pl index 6d9022ff87..eab5fdd640 100755 --- a/catalogue/updateitem.pl +++ b/catalogue/updateitem.pl @@ -39,6 +39,7 @@ my $itemnotes_nonpublic=$cgi->param('itemnotes_nonpublic'); my $withdrawn=$cgi->param('withdrawn'); my $damaged=$cgi->param('damaged'); my $exclude_from_local_holds_priority = $cgi->param('exclude_from_local_holds_priority'); +my $bookable=$cgi->param('bookable'); my $confirm=$cgi->param('confirm'); my $dbh = C4::Context->dbh; @@ -75,6 +76,8 @@ elsif ( $op eq "set_public_note" ) { # i.e., itemnotes parameter passed from for } elsif ( $op eq "set_exclude_priority" && $exclude_from_local_holds_priority ne $item_data_hashref->{'exclude_from_local_holds_priority'}) { $item->exclude_from_local_holds_priority($exclude_from_local_holds_priority); $messages = "updated_exclude_from_local_holds_priority=$exclude_from_local_holds_priority&"; +} elsif ( $op eq "set_bookable" && $bookable ne $item_data_hashref->{'bookable'}) { + $item->bookable($bookable); } elsif ( $op eq "set_damaged" && $damaged ne $item_data_hashref->{'damaged'}) { $item->damaged($damaged); } else { diff --git a/installer/data/mysql/atomicupdate/bug_29002.pl b/installer/data/mysql/atomicupdate/bug_29002.pl index 456e9349bd..30d8ca07cc 100755 --- a/installer/data/mysql/atomicupdate/bug_29002.pl +++ b/installer/data/mysql/atomicupdate/bug_29002.pl @@ -1,12 +1,12 @@ use Modern::Perl; return { - bug_number => "29002", + bug_number => "29002", description => "Add bookings table", - up => sub { + up => sub { my ($args) = @_; - my ($dbh, $out) = @$args{qw(dbh out)}; - if( !TableExists( 'bookings' ) ) { + my ( $dbh, $out ) = @$args{qw(dbh out)}; + if ( !TableExists('bookings') ) { $dbh->do(q{ CREATE TABLE `bookings` ( `booking_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'primary key', @@ -25,5 +25,17 @@ return { ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci }); } + + if ( !column_exists( 'items', 'bookable' ) ) { + $dbh->do(q{ + ALTER TABLE items ADD COLUMN `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this this item is available for bookings or not' AFTER `barcode` + }); + } + + if ( !column_exists( 'deleteditems', 'bookable' ) ) { + $dbh->do(q{ + ALTER TABLE items ADD COLUMN `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this this item is available for bookings or not' AFTER `barcode` + }); + } }, -} +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 1e7a663e5b..782077f21a 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -2735,6 +2735,7 @@ CREATE TABLE `deleteditems` ( `biblionumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from biblio table used to link this item to the right bib record', `biblioitemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from the biblioitems table to link to item to additional information', `barcode` varchar(20) DEFAULT NULL COMMENT 'item barcode (MARC21 952$p)', + `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this this item is available for bookings or not', `dateaccessioned` date DEFAULT NULL COMMENT 'date the item was acquired or added to Koha (MARC21 952$d)', `booksellerid` longtext DEFAULT NULL COMMENT 'where the item was purchased (MARC21 952$e)', `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that owns this item (MARC21 952$a)', @@ -3961,6 +3962,7 @@ CREATE TABLE `items` ( `biblionumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from biblio table used to link this item to the right bib record', `biblioitemnumber` int(11) NOT NULL DEFAULT 0 COMMENT 'foreign key from the biblioitems table to link to item to additional information', `barcode` varchar(20) DEFAULT NULL COMMENT 'item barcode (MARC21 952$p)', + `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'boolean value defining whether this this item is available for bookings or not', `dateaccessioned` date DEFAULT NULL COMMENT 'date the item was acquired or added to Koha (MARC21 952$d)', `booksellerid` longtext DEFAULT NULL COMMENT 'where the item was purchased (MARC21 952$e)', `homebranch` varchar(10) DEFAULT NULL COMMENT 'foreign key from the branches table for the library that owns this item (MARC21 952$a)', diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc index 60ce97db40..5869598de8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/biblio-view-menu.inc @@ -50,6 +50,7 @@ Items + [% IF ( Biblio.CanBook(biblio_object_id) ) %] [%- IF ( bookingsview ) -%]
  • [%- ELSE -%] @@ -57,6 +58,7 @@ [%- END -%] Bookings
  • + [% END %] [%- IF ( CAN_user_reserveforothers ) -%] [%- IF ( holdsview ) -%] diff --git a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc index 93d26e7426..41c8d1ed50 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc +++ b/koha-tmpl/intranet-tmpl/prog/en/includes/cat-toolbar.inc @@ -1,4 +1,5 @@ [% USE Context %] +[% USE Biblio %] [% INCLUDE 'blocking_errors.inc' %]
    @@ -194,7 +195,9 @@ [% END %] [% END %] +[% IF Biblio.CanBook(biblionumber) %]
    +[% END %] [% IF Koha.Preference('ArticleRequests') %] diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt index 673366ce6c..ba14842bc5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -317,6 +317,7 @@
  • Withdrawn on:[% ITEM_DAT.withdrawn_on | $KohaDates %]
  • [% END %] [% END %] +
    @@ -344,6 +345,30 @@ +
  • + Bookable: + [% IF ( CAN_user_circulate ) %] +
    + + + + + + +
    + [% ELSE %] + [% IF ITEM_DAT.bookable == 1 %] Yes [% ELSE %] No [% END %] + [% END %] +
  • + -- 2.39.5