From 7bcc15b0b71ab446378432c74f2209c93b94b147 Mon Sep 17 00:00:00 2001 From: Emmi Takkinen Date: Tue, 8 Apr 2025 15:20:35 +0300 Subject: [PATCH] Bug 36957: Add new syspref CancelTransitWhenItemFloats and branchtransfers.cancelation_reason ItemArrivedToFloatBranch MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When item is in transfer and it is checked in in a library where it could float, a notification/pop-up about transport will appear on the screen. User must end the transfer by clicking “Cancel transfer”-button. Only then will the item end the transport and start floating in the holding library. This patch adds new system preference "CancelTransitWhenItemFloats". If it's enabled and item is checked in in a library where it can float Koha no longer asks user to cancel transfer. Instead transfer is automatically cancelled and column branchtransfers.cancelation_reason is filled with a new value "ItemArrivedToFloatBranch". To test: 1. Create a new floating group and add libraries A and B to it. 2. Find an item which is in transit to branch A. 3. Change your library as library B. 4. Attempt to check in item you found. => Wrong transfer notification is displayed. 5. Apply this patch, run perl installer/data/mysql/updatedatabase.pl and restart services. 6. Enable new systempreference "CancelTransitWhenItemFloats". 7. Check in same item you found (or find new one to check in). => Notification isn't displayed. => Check your database and confirm that trasfer was cancelled with cancelation_reason as "ItemArrivedToFloatBranch" by running following query in your database: select * from branchtransfers where itemnumber = (select itemnumber from items where barcode = "[barcode of checked in item]"); 8. Change your library as library C (that isn't in the same float group as A and B). 9. Attempt to check in an item in transit to branch A. => Wrong transfer notification is displayed. 10 Disable systempreference "CancelTransitWhenItemFloats". 11. Change your libary as library B and attempt to check in an item in transit to library A. => Wrong transfer notification is displayed. Also prove t/db_dependent/Circulation.t Sponsored-by: Koha-Suomi Oy --- C4/Circulation.pm | 6 ++- .../data/mysql/atomicupdate/bug_36957.pl | 43 +++++++++++++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/circulation.pref | 7 +++ 4 files changed, 56 insertions(+), 1 deletion(-) create mode 100755 installer/data/mysql/atomicupdate/bug_36957.pl diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 31794b7c02..6002507057 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -2407,7 +2407,11 @@ sub AddReturn { # if we have a transfer to complete, we update the line of transfers with the datearrived if ($transfer) { $validTransfer = 0; - if ( $transfer->in_transit ) { + # cancel transfer if item can float but it wasn't checked in homebranch + if ( C4::Context->preference('CancelTransitWhenItemFloats') && $validate_float && $branch ne $item->homebranch ) + { + $transfer->cancel( { reason => 'ItemArrivedToFloatBranch', force => 1 } ); + } elsif ( $transfer->in_transit ) { if ( $transfer->tobranch eq $branch ) { $transfer->receive; $messages->{'TransferArrived'} = $transfer->frombranch; diff --git a/installer/data/mysql/atomicupdate/bug_36957.pl b/installer/data/mysql/atomicupdate/bug_36957.pl new file mode 100755 index 0000000000..f0aade87d7 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_36957.pl @@ -0,0 +1,43 @@ +use Modern::Perl; +use Koha::Installer::Output qw(say_warning say_success say_info); + +return { + bug_number => "36957", + description => + "Add CancelTransitWhenItemFloats system preference and 'ItemArrivedToFloatBranch' to branchtransfers.cancellation_reason enum", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES ('CancelTransitWhenItemFloats','0',NULL,'Cancels items transit automatically if it arrives to a branch where it can float','YesNo')} + ); + + say_success( $out, "Added system preference 'CancelTransitWhenItemFloats'" ); + + $dbh->do( + q{ + alter table + `branchtransfers` + modify column + `cancellation_reason` enum( + 'Manual', + 'StockrotationAdvance', + 'StockrotationRepatriation', + 'ReturnToHome', + 'ReturnToHolding', + 'RotatingCollection', + 'Reserve', + 'LostReserve', + 'CancelReserve', + 'ItemLost', + 'WrongTransfer', + 'ItemArrivedToFloatBranch' + ) DEFAULT NULL + after `reason` + } + ); + + say_success( $out, "Added 'ItemArrivedToFloatBranch' to branchtransfers.cancellation_reason enum" ); + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index 2bf9d0b648..b0323b98b8 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -139,6 +139,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('CalculateFundValuesIncludingTax', '1', NULL, 'Include tax in the calculated fund values (spent, ordered) for all supplier configurations', 'YesNo'), ('CalendarFirstDayOfWeek','0','0|1|2|3|4|5|6','Select the first day of week to use in the calendar.','Choice'), ('CancelOrdersInClosedBaskets', '0', NULL, 'Allow/Do not allow cancelling order lines in closed baskets.', 'YesNo'), +('CancelTransitWhenItemFloats','0',NULL,'Cancels items transit automatically if it arrives to a branch where it can float','YesNo'), ('CanMarkHoldsToPullAsLost','do_not_allow','do_not_allow|allow|allow_and_notify','Add a button to the "Holds to pull" screen to mark an item as lost and notify the patron.','Choice'), ('canreservefromotherbranches','1','','With Independent branches on, can a user from one library place a hold on an item from another library','YesNo'), ('CardnumberLength', '', '', 'Set a length for card numbers with a maximum of 32 characters.', 'Free'), 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 291c6ccec6..699d66085e 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 @@ -757,6 +757,13 @@ Circulation: 1: Store 0: "Don't store" - 'the last patron to return an item. This setting is independent of the opacreadinghistory and AnonymousPatron system preferences.' + - + - pref: CancelTransitWhenItemFloats + default: 0 + choices: + 1: Do + 0: "Don't" + - 'cancel transit automatically when item arrives to branch where it can float.' Holds policy: - - Default the holds ratio report to -- 2.34.1