From 914eaadb0e6cc51a3913fc56ced72ba69bd097a0 Mon Sep 17 00:00:00 2001
From: Emmi Takkinen
Date: Wed, 8 Sep 2021 08:58:14 +0300
Subject: [PATCH 3/3] Bug 9525: Add option to define float groups and rules for
float
Bug 22284 introduced ability to create hold groups.
We should have ability to create float groups in
same manner. This patch adds checkbox "Is local
float group" to group creation feature and new return
policy "Item floats by librarygroup".
To test:
1. Add new float group and some libraries to it.
2. From circulation and fine rules, set default
return policy as "Item floats by library group".
3. Check out an item for a patron.
4. Set library as one that belongs in the same
float group.
5. Check in the item.
=> Observe that notice for transfer doesn't pop up.
6. Check out again.
7. This time set library as one that doen's
belong in the same float group.
8. Check in.
=> Observe that notice for transfer pops up.
Experiment this feature by changing return policy
per library, item type etc.
Also prove t/db_dependent/Koha/Libraries.t
Sponsored-by: Koha-Suomi Oy
---
C4/Circulation.pm | 14 ++++++-
Koha/Library.pm | 42 +++++++++++++++++++
admin/library_groups.pl | 4 ++
circ/returns.pl | 6 ++-
.../prog/en/modules/admin/library_groups.tt | 27 ++++++++++--
.../prog/en/modules/admin/smart-rules.tt | 10 +++++
t/db_dependent/Koha/Libraries.t | 32 ++++++++++++++
7 files changed, 128 insertions(+), 7 deletions(-)
diff --git a/C4/Circulation.pm b/C4/Circulation.pm
index 4f2e359b55..74a092e078 100644
--- a/C4/Circulation.pm
+++ b/C4/Circulation.pm
@@ -1925,6 +1925,7 @@ returnbranch => branch to which to return item. Possible values:
noreturn: do not return, let item remain where checked in (floating collections)
homebranch: return to item's home branch
holdingbranch: return to issuer branch
+ returnbylibrarygroup: if item is returned to float group library, let it float
This searches branchitemrules in the following order:
@@ -2084,8 +2085,19 @@ sub AddReturn {
# full item data, but no borrowernumber or checkout info (no issue)
my $hbr = GetBranchItemRule($item->homebranch, $itemtype)->{'returnbranch'} || "homebranch";
+ # check if returnbranch and homebranch belong to the same float group
+ my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $branch });
# get the proper branch to which to return the item
- my $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $branch;
+ my $returnbranch;
+ if($hbr eq 'noreturn'){
+ $returnbranch = $branch;
+ }elsif($hbr eq 'returnbylibrarygroup'){
+ # if library isn't in same the float group, transfer item to homebranch
+ $hbr = 'homebranch';
+ $returnbranch = $validate_float ? $branch : $item->$hbr;
+ }else{
+ $returnbranch = $item->$hbr;
+ }
# if $hbr was "noreturn" or any other non-item table value, then it should 'float' (i.e. stay at this branch)
my $transfer_trigger = $hbr eq 'homebranch' ? 'ReturnToHome' : $hbr eq 'holdingbranch' ? 'ReturnToHolding' : undef;
diff --git a/Koha/Library.pm b/Koha/Library.pm
index 48e125529b..fbd33532d0 100644
--- a/Koha/Library.pm
+++ b/Koha/Library.pm
@@ -313,6 +313,48 @@ sub to_api_mapping {
};
}
+=head3 get_float_group_libraries
+
+Return all libraries belonging to the same float group
+
+=cut
+
+sub get_float_libraries {
+ my ( $self ) = @_;
+
+ my $library_groups = $self->library_groups;
+ my @float_libraries;
+
+ while ( my $library_group = $library_groups->next ) {
+ my $root = Koha::Library::Groups->get_root_ancestor({id => $library_group->id});
+ if($root->ft_local_float_group) {
+ push @float_libraries, $root->all_libraries;
+ }
+ }
+
+ my %seen;
+ @float_libraries =
+ grep { !$seen{ $_->id }++ } @float_libraries;
+
+ return Koha::Libraries->search({ branchcode => { '-in' => [ keys %seen ] } });
+}
+
+=head3 validate_float_sibling
+
+Return if given library is a valid float group member
+
+=cut
+
+sub validate_float_sibling {
+ my ( $self, $params ) = @_;
+
+ return 1 if $params->{branchcode} eq $self->id;
+
+ my $branchcode = $params->{branchcode};
+ return $self->get_float_libraries->search( { branchcode => $branchcode } )
+ ->count > 0;
+}
+
=head2 Internal methods
=head3 _type
diff --git a/admin/library_groups.pl b/admin/library_groups.pl
index 5284a881f4..b0ab345b01 100755
--- a/admin/library_groups.pl
+++ b/admin/library_groups.pl
@@ -50,6 +50,7 @@ if ( $action eq 'add' ) {
my $ft_search_groups_opac = $cgi->param('ft_search_groups_opac') || 0;
my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
+ my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0;
if ( !$branchcode && Koha::Library::Groups->search( { title => $title } )->count() ) {
$template->param( error_duplicate_title => $title );
@@ -65,6 +66,7 @@ if ( $action eq 'add' ) {
ft_search_groups_opac => $ft_search_groups_opac,
ft_search_groups_staff => $ft_search_groups_staff,
ft_local_hold_group => $ft_local_hold_group,
+ ft_local_float_group => $ft_local_float_group,
branchcode => $branchcode,
}
)->store();
@@ -85,6 +87,7 @@ elsif ( $action eq 'edit' ) {
my $ft_search_groups_opac = $cgi->param('ft_search_groups_opac') || 0;
my $ft_search_groups_staff = $cgi->param('ft_search_groups_staff') || 0;
my $ft_local_hold_group = $cgi->param('ft_local_hold_group') || 0;
+ my $ft_local_float_group = $cgi->param('ft_local_float_group') || 0;
if ($id) {
my $group = Koha::Library::Groups->find($id);
@@ -97,6 +100,7 @@ elsif ( $action eq 'edit' ) {
ft_search_groups_opac => $ft_search_groups_opac,
ft_search_groups_staff => $ft_search_groups_staff,
ft_local_hold_group => $ft_local_hold_group,
+ ft_local_float_group => $ft_local_float_group,
}
)->store();
diff --git a/circ/returns.pl b/circ/returns.pl
index f98907187a..359daa6b0f 100755
--- a/circ/returns.pl
+++ b/circ/returns.pl
@@ -303,8 +303,10 @@ if ($barcode) {
# make sure return branch respects home branch circulation rules, default to homebranch
my $hbr = GetBranchItemRule($item->homebranch, $itemtype ? $itemtype->itemtype : undef )->{'returnbranch'} || "homebranch";
- $returnbranch = $hbr ne 'noreturn' ? $item->$hbr : $userenv_branch; # can be noreturn, homebranch or holdingbranch
-
+ my $validate_float = Koha::Libraries->find( $item->homebranch )->validate_float_sibling({ branchcode => $userenv_branch });
+ # get the proper branch to which to return the item
+ # if library isn't in same the float group, transfer item to homelibrary
+ $returnbranch = $hbr eq 'noreturn' ? $userenv_branch : $hbr eq 'returnbylibrarygroup' ? $validate_float ? $userenv_branch : $item->homebranch : $item->$hbr;
my $materials = $item->materials;
my $descriptions = Koha::AuthorisedValues->get_description_by_koha_field({frameworkcode => '', kohafield =>'items.materials', authorised_value => $materials });
$materials = $descriptions->{lib} // $materials;
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt
index 94e1ec0af4..46c697fff1 100644
--- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt
+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/library_groups.tt
@@ -147,6 +147,12 @@
Is local hold group