Bug 22284: Add "patron's hold group" as new hold_fulfillment_policy option
authorAgustin Moyano <agustinmoyano@theke.io>
Tue, 28 May 2019 02:49:05 +0000 (23:49 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Fri, 3 Jan 2020 12:58:05 +0000 (12:58 +0000)
This patch adds "patron's hold group" as a new option to Hold pickup library match

To test:
1. Set ReservesControlBranch preference to item.
2. Create a hold group
3. Go to circulation and fines rules
SUCCESS => in 'Hold pickup library match' there is a new option called "patron's hold group"
4. In a library not in hold group set 'Hold policy' to "any" and 'Hold pickup library match' to "patron's hold group"
5. Search for a user in the hold group
6. 'Search to hold' for items of the library of step 4
7. Select an item and 'Place hold for [user]'
SUCCESS => in 'Pickup at' you should see patron's hold group as options
8. In OPAC sign in as the same user of step 5
9. Search for the item in step 7
SUCCESS => in 'Pick up locations' you should see patron's hold group as options
10. Sign off

Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Liz Rea <wizzyrea@gmail.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

C4/Reserves.pm
Koha/Item.pm
Koha/Libraries.pm
koha-tmpl/intranet-tmpl/prog/en/modules/admin/smart-rules.tt
reserve/request.pl

index 5f11c31..b953cf8 100644 (file)
@@ -509,6 +509,9 @@ sub CanItemBeReserved {
         unless ($branchitemrule->{hold_fulfillment_policy} ne 'holdgroup' || $item_library->validate_hold_sibling( {branchcode => $pickup_branchcode} )) {
             return { status => 'pickupNotInHoldGroup' };
         }
+        unless ($branchitemrule->{hold_fulfillment_policy} ne 'patrongroup' || Koha::Libraries->find({branchcode => $borrower->{branchcode}})->validate_hold_sibling({branchcode => $pickup_branchcode})) {
+            return { status => 'pickupNotInHoldGroup' };
+        }
     }
 
     return { status => 'OK' };
index 3cab6d2..8d791ab 100644 (file)
@@ -313,19 +313,19 @@ sub pickup_locations {
     my $branchitemrule =
       C4::Circulation::GetBranchItemRule( $circ_control_branch, $self->itype );
 
-    my $branch_control = C4::Context->preference('HomeOrHoldingBranch');
-    my $library = $branch_control eq 'holdingbranch' ? $self->holding_branch : $self->home_branch;
-
     my @libs;
     if(defined $patron) {
-        return @libs if $branchitemrule->{holdallowed} == 3 && !$library->validate_hold_sibling( {branchcode => $patron->branchcode} );
-        return @libs if $branchitemrule->{holdallowed} == 1 && $library->branchcode ne $patron->branchcode;
+        return @libs if $branchitemrule->{holdallowed} == 3 && !$self->home_branch->validate_hold_sibling( {branchcode => $patron->branchcode} );
+        return @libs if $branchitemrule->{holdallowed} == 1 && $self->home_branch->branchcode ne $patron->branchcode;
     }
 
     if ($branchitemrule->{hold_fulfillment_policy} eq 'holdgroup') {
-        @libs  = $library->get_hold_libraries;
-        my $circ_control_library = Koha::Libraries->find($circ_control_branch);
-        push @libs, $circ_control_library unless scalar(@libs) > 0;
+        @libs  = $self->home_branch->get_hold_libraries;
+        push @libs, $self->home_branch unless scalar(@libs) > 0;
+    } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'patrongroup') {
+        my $plib = Koha::Libraries->find({ branchcode => $patron->branchcode});
+        @libs  = $plib->get_hold_libraries;
+        push @libs, $self->home_branch unless scalar(@libs) > 0;
     } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'homebranch') {
         push @libs, $self->home_branch;
     } elsif ($branchitemrule->{hold_fulfillment_policy} eq 'holdingbranch') {
index bc92f0b..ebd552b 100644 (file)
@@ -28,6 +28,7 @@ use Koha::Database;
 use Koha::Item::Transfer::Limits;
 use Koha::Items;
 use Koha::Library;
+use Koha::Patrons;
 
 use base qw(Koha::Objects);
 
@@ -75,7 +76,7 @@ sub pickup_locations {
         );
     }
     unless (! defined $patron || ref($patron) eq 'Koha::Patron') {
-        $patron = Koha::Items->find($patron);
+        $patron = Koha::Patrons->find($patron);
     }
 
     # Select libraries that are configured as pickup locations
index 7018200..dac351b 100644 (file)
                                 </option>
                             [% END %]
 
+                            [% IF hold_fulfillment_policy == 'patrongroup' %]
+                                <option value="patrongroup" selected="selected">
+                                    patron's hold group
+                                </option>
+                            [% ELSE %]
+                                <option value="patrongroup">
+                                    patron's hold group
+                                </option>
+                            [% END %]
+
                             [% IF hold_fulfillment_policy == 'homebranch' %]
                                 <option value="homebranch" selected="selected">
                                     item's home library
                                     <span>item's home library</span>
                                 [% ELSIF hold_fulfillment_policy == 'holdgroup' %]
                                     <span>item's hold group</span>
+                                [% ELSIF hold_fulfillment_policy == 'patrongroup' %]
+                                    <span>patron's hold group</span>
                                 [% ELSIF hold_fulfillment_policy == 'holdingbranch' %]
                                     <span>item's holding library</span>
                                 [% END %]
                                 item's hold group
                             </option>
 
+                            <option value="patrongroup">
+                                patron's hold group
+                            </option>
+
                             <option value="homebranch">
                                 item's home library
                             </option>
index 6b6b99e..6b613d8 100755 (executable)
@@ -565,7 +565,7 @@ foreach my $biblionumber (@biblionumbers) {
                     if($branchitemrule->{'hold_fulfillment_policy'} eq 'any' ) {
                         $item->{pickup_locations} = 'Any library';
                     } else {
-                        $item->{pickup_locations} = join (', ', map { $_->{branchname} } Koha::Items->find($itemnumber)->pickup_locations());
+                        $item->{pickup_locations} = join (', ', map { $_->{branchname} } Koha::Items->find($itemnumber)->pickup_locations({ patron => $patron }));
                     }
 
                     push( @available_itemtypes, $item->{itype} );