View | Details | Raw Unified | Return to bug 14514
Collapse All | Expand All

(-)a/C4/HoldsQueue.pm (+54 lines)
Lines 389-394 sub MapItemsToHoldRequests { Link Here
389
389
390
    # figure out which item-level requests can be filled
390
    # figure out which item-level requests can be filled
391
    my $num_items_remaining = scalar(@$available_items);
391
    my $num_items_remaining = scalar(@$available_items);
392
393
    # Look for Local Holds Priority matches first
394
    if ( C4::Context->preference('LocalHoldsPriority') ) {
395
        my $LocalHoldsPriorityPatronControl =
396
          C4::Context->preference('LocalHoldsPriorityPatronControl');
397
        my $LocalHoldsPriorityItemControl =
398
          C4::Context->preference('LocalHoldsPriorityItemControl');
399
400
        foreach my $request (@$hold_requests) {
401
            last if $num_items_remaining == 0;
402
403
            my $local_hold_match;
404
            foreach my $item (@$available_items) {
405
                next
406
                  if ( !$item->{holdallowed} )
407
                  || ( $item->{holdallowed} == 1
408
                    && $item->{homebranch} ne $request->{borrowerbranch} );
409
410
                my $local_holds_priority_item_branchcode =
411
                  $item->{$LocalHoldsPriorityItemControl};
412
413
                my $local_holds_priority_patron_branchcode =
414
                  ( $LocalHoldsPriorityPatronControl eq 'PickupLibrary' )
415
                  ? $request->{branchcode}
416
                  : ( $LocalHoldsPriorityPatronControl eq 'HomeLibrary' )
417
                  ? $request->{borrowerbranch}
418
                  : undef;
419
420
                $local_hold_match =
421
                  $local_holds_priority_item_branchcode eq
422
                  $local_holds_priority_patron_branchcode;
423
424
                if ($local_hold_match) {
425
                    if ( exists $items_by_itemnumber{ $item->{itemnumber} }
426
                        and not exists $allocated_items{ $item->{itemnumber} } )
427
                    {
428
                        $item_map{ $item->{itemnumber} } = {
429
                            borrowernumber => $request->{borrowernumber},
430
                            biblionumber   => $request->{biblionumber},
431
                            holdingbranch  => $item->{holdingbranch},
432
                            pickup_branch  => $request->{branchcode}
433
                              || $request->{borrowerbranch},
434
                            item_level   => 0,
435
                            reservedate  => $request->{reservedate},
436
                            reservenotes => $request->{reservenotes},
437
                        };
438
                        $allocated_items{ $item->{itemnumber} }++;
439
                        $num_items_remaining--;
440
                    }
441
                }
442
            }
443
        }
444
    }
445
392
    foreach my $request (@$hold_requests) {
446
    foreach my $request (@$hold_requests) {
393
        last if $num_items_remaining == 0;
447
        last if $num_items_remaining == 0;
394
448
(-)a/t/db_dependent/HoldsQueue.t (-2 / +81 lines)
Lines 8-14 Link Here
8
8
9
use Modern::Perl;
9
use Modern::Perl;
10
10
11
use Test::More tests => 38;
11
use Test::More tests => 42;
12
use Data::Dumper;
12
use Data::Dumper;
13
13
14
use C4::Branch;
14
use C4::Branch;
Lines 63-68 my $itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => Link Here
63
#Set up the stage
63
#Set up the stage
64
# Sysprefs and cost matrix
64
# Sysprefs and cost matrix
65
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
65
C4::Context->set_preference('HoldsQueueSkipClosed', 0);
66
C4::Context->set_preference('LocalHoldsPriority', 0);
66
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
67
$dbh->do("UPDATE systempreferences SET value = ? WHERE variable = 'StaticHoldsQueueWeight'", undef,
67
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
68
         join( ',', @other_branches, $borrower_branchcode, $least_cost_branch_code));
68
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
69
$dbh->do("UPDATE systempreferences SET value = '0' WHERE variable = 'RandomizeHoldsQueueWeight'");
Lines 333-338 $holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice Link Here
333
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
334
is( scalar( @$holds_queue ), 2, "Holds not filled with items from closed libraries" );
334
C4::Context->set_preference( 'HoldsQueueSkipClosed', 0 );
335
C4::Context->set_preference( 'HoldsQueueSkipClosed', 0 );
335
336
337
## Test LocalHoldsPriority
338
C4::Context->set_preference('LocalHoldsPriority', 1);
339
340
$dbh->do("DELETE FROM default_circ_rules");
341
$dbh->do("INSERT INTO default_circ_rules ( holdallowed ) VALUES ( 2 )");
342
$dbh->do("DELETE FROM issues");
343
344
# Test homebranch = patron branch
345
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
346
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch');
347
C4::Context->clear_syspref_cache();
348
$dbh->do("DELETE FROM reserves");
349
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
350
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
351
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
352
353
$dbh->do("DELETE FROM items");
354
# barcode, homebranch, holdingbranch, itemtype
355
$items_insert_sth->execute( $barcode + 4, $branchcodes[2], $branchcodes[0] );
356
357
C4::HoldsQueue::CreateQueue();
358
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
359
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's home library");
360
361
# Test holdingbranch = patron branch
362
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'HomeLibrary');
363
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
364
C4::Context->clear_syspref_cache();
365
$dbh->do("DELETE FROM reserves");
366
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
367
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
368
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[0], 3 );
369
370
$dbh->do("DELETE FROM items");
371
# barcode, homebranch, holdingbranch, itemtype
372
$items_insert_sth->execute( $barcode + 4, $branchcodes[0], $branchcodes[2] );
373
374
C4::HoldsQueue::CreateQueue();
375
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
376
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library");
377
378
# Test holdingbranch = pickup branch
379
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary');
380
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'holdingbranch');
381
C4::Context->clear_syspref_cache();
382
$dbh->do("DELETE FROM reserves");
383
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
384
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
385
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[2], 3 );
386
387
$dbh->do("DELETE FROM items");
388
# barcode, homebranch, holdingbranch, itemtype
389
$items_insert_sth->execute( $barcode + 4, $branchcodes[0], $branchcodes[2] );
390
391
C4::HoldsQueue::CreateQueue();
392
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
393
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library");
394
395
# Test homebranch = pickup branch
396
C4::Context->set_preference('LocalHoldsPriorityPatronControl', 'PickupLibrary');
397
C4::Context->set_preference('LocalHoldsPriorityItemControl', 'homebranch');
398
C4::Context->clear_syspref_cache();
399
$dbh->do("DELETE FROM reserves");
400
$sth->execute( $borrower1->{borrowernumber}, $biblionumber, $branchcodes[0], 1 );
401
$sth->execute( $borrower2->{borrowernumber}, $biblionumber, $branchcodes[0], 2 );
402
$sth->execute( $borrower3->{borrowernumber}, $biblionumber, $branchcodes[2], 3 );
403
404
$dbh->do("DELETE FROM items");
405
# barcode, homebranch, holdingbranch, itemtype
406
$items_insert_sth->execute( $barcode + 4, $branchcodes[2], $branchcodes[0] );
407
408
C4::HoldsQueue::CreateQueue();
409
$holds_queue = $dbh->selectall_arrayref("SELECT * FROM tmp_holdsqueue", { Slice => {} });
410
is( $holds_queue->[0]->{cardnumber}, $borrower3->{cardnumber}, "Holds queue giving priority to patron who's home library matches item's holding library");
411
412
C4::Context->set_preference('LocalHoldsPriority', 0);
413
## End testing of LocalHoldsPriority
414
415
336
# Bug 14297
416
# Bug 14297
337
$itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype};
417
$itemtype = $builder->build({ source => 'Itemtype', value => { notforloan => 0 } })->{itemtype};
338
$borrowernumber = $borrower3->{borrowernumber};
418
$borrowernumber = $borrower3->{borrowernumber};
339
- 

Return to bug 14514