From d66a93b575c9c4af0d859fcbac7a27baa8684081 Mon Sep 17 00:00:00 2001 From: Thibaud Guillot Date: Thu, 25 Jan 2024 14:14:07 +0100 Subject: [PATCH] Bug 35906: Add bookable option on itemtype MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Actually new "booking" feature can be set on an item but no directly on an itemtype. This patch adds this possibility. Test plan: 1) Test this new feature on an item as it were currently working. 2) Apply this patch 3) Run updatedatabase.pl 4) Reload Schema by running update_dbix_class_files.pl 5) Edit an itemtype, there is a new checkbox to add 'bookable' option 6) Test it with item with this itemtype, if there is 1 item at least you will see 'Booking' tab. 7) You now have a new setting on the item bookable option to 'Follow itemtype" Sponsored by: Association de Gestion des Ĺ’uvres Sociales d'Inria (AGOS) --- Koha/ItemType.pm | 1 + Koha/Items.pm | 5 ++++- Koha/REST/V1/Biblios.pm | 3 +++ admin/itemtypes.pl | 3 +++ .../Bug_35906_add-column-bookable-itemtype.pl | 21 +++++++++++++++++++ installer/data/mysql/kohastructure.sql | 1 + installer/data/mysql/mandatory/sysprefs.sql | 1 + .../prog/en/modules/admin/itemtypes.tt | 11 ++++++++++ .../admin/preferences/circulation.pref | 7 +++++++ .../prog/en/modules/catalogue/moredetail.tt | 8 ++++--- 10 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/Bug_35906_add-column-bookable-itemtype.pl diff --git a/Koha/ItemType.pm b/Koha/ItemType.pm index fb88518c257..f4c0c4aee98 100644 --- a/Koha/ItemType.pm +++ b/Koha/ItemType.pm @@ -234,6 +234,7 @@ sub to_api_mapping { rentalcharge_daily_calendar => 'daily_rental_charge_calendar', rentalcharge_hourly => 'hourly_rental_charge', rentalcharge_hourly_calendar => 'hourly_rental_charge_calendar', + bookable_itemtype => 'bookable_itemtype', }; } diff --git a/Koha/Items.pm b/Koha/Items.pm index f3edb776856..68f76a07f02 100644 --- a/Koha/Items.pm +++ b/Koha/Items.pm @@ -169,7 +169,10 @@ Returns a new resultset, containing only those items that are allowed to be book sub filter_by_bookable { my ($self) = @_; - my $params = { bookable => 1 }; + my $params = + C4::Context->preference('item-level_booking') == 1 + ? { bookable => 1 } + : { itype => { -in => \'SELECT itemtype FROM itemtypes WHERE bookable = 1' } }; return $self->search($params); } diff --git a/Koha/REST/V1/Biblios.pm b/Koha/REST/V1/Biblios.pm index edb51653146..f152baedbf4 100644 --- a/Koha/REST/V1/Biblios.pm +++ b/Koha/REST/V1/Biblios.pm @@ -291,6 +291,9 @@ sub get_items { my $biblio = Koha::Biblios->find( { biblionumber => $c->param('biblio_id') }, { prefetch => ['items'] } ); my $bookable_only = $c->param('bookable'); + # Deletion of parameter to avoid filtering on the items table in the case of bookings on 'itemtype' + $c->req->params->remove('bookable'); + unless ($biblio) { return $c->render( status => 404, diff --git a/admin/itemtypes.pl b/admin/itemtypes.pl index 684f9377dbc..b5dbc7c98c6 100755 --- a/admin/itemtypes.pl +++ b/admin/itemtypes.pl @@ -98,6 +98,7 @@ if ( $op eq 'add_form' ) { my $rentalcharge_daily_calendar = $input->param('rentalcharge_daily_calendar') // 0; my $rentalcharge_hourly_calendar = $input->param('rentalcharge_hourly_calendar') // 0; my $automatic_checkin = $input->param('automatic_checkin') // 0; + my $bookable = $input->param('bookable')// 0; if ( $itemtype and $is_a_modif ) { # it's a modification $itemtype->description($description); @@ -118,6 +119,7 @@ if ( $op eq 'add_form' ) { $itemtype->rentalcharge_daily_calendar($rentalcharge_daily_calendar); $itemtype->rentalcharge_hourly_calendar($rentalcharge_hourly_calendar); $itemtype->automatic_checkin($automatic_checkin); + $itemtype->bookable($bookable); eval { $itemtype->store; @@ -151,6 +153,7 @@ if ( $op eq 'add_form' ) { rentalcharge_daily_calendar => $rentalcharge_daily_calendar, rentalcharge_hourly_calendar => $rentalcharge_hourly_calendar, automatic_checkin => $automatic_checkin, + bookable => $bookable, } ); eval { diff --git a/installer/data/mysql/atomicupdate/Bug_35906_add-column-bookable-itemtype.pl b/installer/data/mysql/atomicupdate/Bug_35906_add-column-bookable-itemtype.pl new file mode 100644 index 00000000000..642505fd2fd --- /dev/null +++ b/installer/data/mysql/atomicupdate/Bug_35906_add-column-bookable-itemtype.pl @@ -0,0 +1,21 @@ +use Modern::Perl; + +return { + bug_number => "35906", + description => "Add bookable column on itemtypes table", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do(q{ + INSERT IGNORE INTO systempreferences (`variable`, `value`, `options`, `explanation`, `type`) VALUES ('item-level_booking', 1, '', 'enables item type level for future booking', 'YesNo'); + }); + + $dbh->do(q{ + ALTER TABLE itemtypes ADD IF NOT EXISTS bookable INT(1) DEFAULT 0 + }); + + say $out "Added new system preference 'item-level_booking'"; + say $out "Added column 'itemtypes.bookable'"; + }, +}; diff --git a/installer/data/mysql/kohastructure.sql b/installer/data/mysql/kohastructure.sql index 3828776962c..b89040f26d6 100644 --- a/installer/data/mysql/kohastructure.sql +++ b/installer/data/mysql/kohastructure.sql @@ -4123,6 +4123,7 @@ CREATE TABLE `itemtypes` ( `hideinopac` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Hide the item type from the search options in OPAC', `searchcategory` varchar(80) DEFAULT NULL COMMENT 'Group this item type with others with the same value on OPAC search options', `automatic_checkin` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'If automatic checkin is enabled for items of this type', + `bookable` tinyint(1) NOT NULL DEFAULT 0 COMMENT 'Activate bookable feature for items related to this item type', PRIMARY KEY (`itemtype`), UNIQUE KEY `itemtype` (`itemtype`), KEY `itemtypes_ibfk_1` (`parent_type`), diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 0b264fb9280..de86ca7778a 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -347,6 +347,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('IssueLostItem','alert','Defines what should be done when an attempt is made to issue an item that has been marked as lost.','alert|confirm|nothing','Choice'), ('IssuingInProcess','0',NULL,'If ON, disables fines if the patron is issuing item that accumulate debt','YesNo'), ('item-level_itypes','1','','If ON, enables Item-level Itemtype / Issuing Rules','YesNo'), +('item-level_booking','1','','If ON, enables Item-level for future booking feature','YesNo'), ('itemBarcodeFallbackSearch','0',NULL,'If set, uses scanned item barcodes as a catalogue search if not found as barcodes','YesNo'), ('itemBarcodeInputFilter','','whitespace|T-prefix|cuecat|libsuite8|EAN13','If set, allows specification of a item barcode input filter','Choice'), ('itemcallnumber','',NULL,'The MARC field/subfield that is used to calculate the itemcallnumber (Dewey would be 082ab or 092ab; LOC would be 050ab or 090ab) could be 852hi from an item record','free'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt index b9ea060e304..d93cee3b87f 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/itemtypes.tt @@ -258,6 +258,17 @@ [% END %] If checked, items will be automatically checked in once they've reached their due date. This feature requires the misc/cronjobs/automatic_checkin.pl cronjob. Ask your system administrator to schedule it. + [% IF Koha.Preference('item-level_booking') == 0 %] +
  • + + [% IF itemtype.bookable %] + + [% ELSE %] + + [% END %] + If checked, all items of this type will be enabled for future bookings. +
  • + [% END %]
  • diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 110b6913ddb..df7fe3b558b 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -1019,6 +1019,13 @@ Circulation: 0: "Don't allow" - holds to be automatically filled after being automatically checked in. - '
    NOTE: This system preference requires the misc/cronjobs/automatic_checkin.pl cronjob. Ask your system administrator to schedule it.' + - + - Use the type of the + - pref: item-level_booking + choices: + 1: item + 0: itemtype + - level to defined witch items can be bookable in future. Patron restrictions: - - pref: PatronRestrictionTypes 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 a00db538ac0..f6a45d0f2a4 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/catalogue/moredetail.tt @@ -351,15 +351,17 @@
  • - Bookable: + + Bookable: + [% IF ( CAN_user_circulate ) %]
    [% INCLUDE 'csrf-token.inc' %] - + [% IF ITEM_DAT.bookable == 1 || ITEM_DAT.effective_itemtype.bookable == 1 %] [% ELSE %] -- 2.30.2