Bug 35906: Add bookable option on itemtype

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) Change new syspref 'item-level_booking' to 'itemtype'
6) Edit an itemtype, there is a new checkbox to add 'bookable' option
7) Test it with item with this itemtype, if there is 1 item at least you
   will see 'Booking' tab.
8) You can change syspref to 'item' to see the current behavior

Note: When item-level_booking is set on 'itemtype' you can change
dropdown option to 'No' on item bookable option.

Sponsored by: Association de Gestion des Œuvres Sociales d'Inria (AGOS)
Signed-off-by: Esther <esther@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Paul Derscheid <paul.derscheid@lmscloud.de>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Thibaud Guillot 2024-01-25 14:14:07 +01:00 committed by Katrin Fischer
parent 94210ae471
commit 39891095a6
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
10 changed files with 57 additions and 4 deletions

View File

@ -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',
};
}

View File

@ -197,7 +197,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);
}

View File

@ -266,6 +266,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');
return $c->render_resource_not_found("Bibliographic record")
unless $biblio;

View File

@ -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 {

View File

@ -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'";
},
};

View File

@ -4143,6 +4143,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`),

View File

@ -355,6 +355,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'),

View File

@ -258,6 +258,17 @@
[% END %]
<span class="hint">If checked, items will be automatically checked in once they've reached their due date. This feature requires the <code>misc/cronjobs/automatic_checkin.pl</code> cronjob. Ask your system administrator to schedule it.</span>
</li>
[% IF Koha.Preference('item-level_booking') == 0 %]
<li>
<label for="bookable">Bookable: </label>
[% IF itemtype.bookable %]
<input type="checkbox" id="bookable" name="bookable" checked="checked" value="1" />
[% ELSE %]
<input type="checkbox" id="bookable" name="bookable" value="1" />
[% END %]
<span class="hint">If checked, all items of this type will be enabled for future bookings.</span>
</li>
[% END %]
<li>
<label for="rentalcharge">Rental charge: </label>
<input type="text" id="rentalcharge" name="rentalcharge" size="10" value="[% itemtype.rentalcharge | $Price on_editing => 1 %]" min="0" />

View File

@ -1089,6 +1089,13 @@ Circulation:
1: "Do"
0: "Don't"
- place a hold when ordering from a suggestion.
-
- 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

View File

@ -344,15 +344,17 @@
</form>
</li>
<li>
<span class="label">Bookable:</span>
<span class="label">
Bookable:
</span>
[% IF ( CAN_user_circulate ) %]
<form action="updateitem.pl" method="post">
[% INCLUDE 'csrf-token.inc' %]
<input type="hidden" name="biblionumber" value="[% ITEM_DAT.biblionumber | html %]" />
<input type="hidden" name="biblioitemnumber" value="[% ITEM_DAT.biblioitemnumber | html %]" />
<input type="hidden" name="itemnumber" value="[% ITEM_DAT.itemnumber | html %]" />
<select name="bookable">
[% IF ITEM_DAT.bookable == 1 %]
<select name="bookable" [% IF ITEM_DAT.effective_itemtype.bookable == 1 && Koha.Preference('item-level_booking') == 0 %]disabled[% END %]>
[% IF ITEM_DAT.bookable == 1 || ITEM_DAT.effective_itemtype.bookable == 1 %]
<option value="1" selected="selected">Yes</option>
<option value="0">No</option>
[% ELSE %]