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

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

Return to bug 14514