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

(-)a/C4/HoldsQueue.pm (-5 / +8 lines)
Lines 32-37 use C4::Biblio; Link Here
32
use C4::Dates qw/format_date/;
32
use C4::Dates qw/format_date/;
33
33
34
use List::Util qw(shuffle);
34
use List::Util qw(shuffle);
35
use List::MoreUtils qw(any);
35
use Data::Dumper;
36
use Data::Dumper;
36
37
37
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
38
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
Lines 354-361 sub MapItemsToHoldRequests { Link Here
354
    return unless scalar(@$hold_requests) > 0;
355
    return unless scalar(@$hold_requests) > 0;
355
    return unless scalar(@$available_items) > 0;
356
    return unless scalar(@$available_items) > 0;
356
357
357
    my $automatic_return = C4::Context->preference("AutomaticItemReturn");
358
359
    # identify item-level requests
358
    # identify item-level requests
360
    my %specific_items_requested = map { $_->{itemnumber} => 1 }
359
    my %specific_items_requested = map { $_->{itemnumber} => 1 }
361
                                   grep { defined($_->{itemnumber}) }
360
                                   grep { defined($_->{itemnumber}) }
Lines 419-425 sub MapItemsToHoldRequests { Link Here
419
        my $pickup_branch = $request->{branchcode} || $request->{borrowerbranch};
418
        my $pickup_branch = $request->{branchcode} || $request->{borrowerbranch};
420
        my ($itemnumber, $holdingbranch);
419
        my ($itemnumber, $holdingbranch);
421
420
422
        my $holding_branch_items = $automatic_return ? undef : $items_by_branch{$pickup_branch};
421
        my $holding_branch_items = $items_by_branch{$pickup_branch};
423
        if ( $holding_branch_items ) {
422
        if ( $holding_branch_items ) {
424
            foreach my $item (@$holding_branch_items) {
423
            foreach my $item (@$holding_branch_items) {
425
                if ( $request->{borrowerbranch} eq $item->{homebranch} ) {
424
                if ( $request->{borrowerbranch} eq $item->{homebranch} ) {
Lines 587-596 sub least_cost_branch { Link Here
587
    #$from - arrayref
586
    #$from - arrayref
588
    my ($to, $from, $transport_cost_matrix) = @_;
587
    my ($to, $from, $transport_cost_matrix) = @_;
589
588
590
# Nothing really spectacular: supply to branch, a list of potential from branches
589
    # Nothing really spectacular: supply to branch, a list of potential from branches
591
# and find the minimum from - to value from the transport_cost_matrix
590
    # and find the minimum from - to value from the transport_cost_matrix
592
    return $from->[0] if @$from == 1;
591
    return $from->[0] if @$from == 1;
593
592
593
    # If the pickup library is in the list of libraries to pull from,
594
    # return that library right away, it is obviously the least costly
595
    return ($to) if any { $_ eq $to } @$from;
596
594
    my ($least_cost, @branch);
597
    my ($least_cost, @branch);
595
    foreach (@$from) {
598
    foreach (@$from) {
596
        my $cell = $transport_cost_matrix->{$to}{$_};
599
        my $cell = $transport_cost_matrix->{$to}{$_};
(-)a/t/db_dependent/HoldsQueue.t (-5 / +7 lines)
Lines 12-18 use C4::Context; Link Here
12
12
13
use Data::Dumper;
13
use Data::Dumper;
14
14
15
use Test::More tests => 18;
15
use Test::More tests => 16;
16
16
17
use C4::Branch;
17
use C4::Branch;
18
use C4::ItemType;
18
use C4::ItemType;
Lines 100-106 my $priority = 1; Link Here
100
# Make a reserve
100
# Make a reserve
101
AddReserve ( $borrower_branchcode, $borrowernumber, $biblionumber, $constraint, $bibitems,  $priority );
101
AddReserve ( $borrower_branchcode, $borrowernumber, $biblionumber, $constraint, $bibitems,  $priority );
102
#                           $resdate, $expdate, $notes, $title, $checkitem, $found
102
#                           $resdate, $expdate, $notes, $title, $checkitem, $found
103
$dbh->do("UPDATE reserves SET reservedate = reservedate - 1");
103
$dbh->do("UPDATE reserves SET reservedate = DATE_SUB( reservedate, INTERVAL 1 DAY )");
104
104
105
# Tests
105
# Tests
106
my $use_cost_matrix_sth = $dbh->prepare("UPDATE systempreferences SET value = ? WHERE variable = 'UseTransportCostMatrix'");
106
my $use_cost_matrix_sth = $dbh->prepare("UPDATE systempreferences SET value = ? WHERE variable = 'UseTransportCostMatrix'");
Lines 121-128 $dbh->do("DELETE FROM items WHERE homebranch = '$borrower_branchcode' AND holdin Link Here
121
# test_queue will flush
121
# test_queue will flush
122
C4::Context->set_preference('AutomaticItemReturn', 1);
122
C4::Context->set_preference('AutomaticItemReturn', 1);
123
# Not sure how to make this test more difficult - holding branch does not matter
123
# Not sure how to make this test more difficult - holding branch does not matter
124
test_queue ('take from holdingbranch AutomaticItemReturn on', 0, $borrower_branchcode, undef);
125
test_queue ('take from holdingbranch AutomaticItemReturn on', 1, $borrower_branchcode, $least_cost_branch_code);
126
124
127
$dbh->do("DELETE FROM tmp_holdsqueue");
125
$dbh->do("DELETE FROM tmp_holdsqueue");
128
$dbh->do("DELETE FROM hold_fill_targets");
126
$dbh->do("DELETE FROM hold_fill_targets");
Lines 148-153 ok( $queue_item Link Here
148
 && $queue_item->{holdingbranch} eq $least_cost_branch_code, "GetHoldsQueueItems" )
146
 && $queue_item->{holdingbranch} eq $least_cost_branch_code, "GetHoldsQueueItems" )
149
  or diag( "Expected item for pick $borrower_branchcode, hold $least_cost_branch_code, got ".Dumper($queue_item) );
147
  or diag( "Expected item for pick $borrower_branchcode, hold $least_cost_branch_code, got ".Dumper($queue_item) );
150
148
149
ok(
150
    C4::HoldsQueue::least_cost_branch( 'B', [ 'A', 'B', 'C' ] ) eq 'B',
151
    'C4::HoldsQueue::least_cost_branch returns the local branch if it is in the list of branches to pull from'
152
);
153
151
# XXX All this tests are for borrower branch pick-up.
154
# XXX All this tests are for borrower branch pick-up.
152
# Maybe needs expanding to homebranch or holdingbranch pick-up.
155
# Maybe needs expanding to homebranch or holdingbranch pick-up.
153
156
154
- 

Return to bug 10628